SCJP Mock Exam 4(9)
添加时间: 2007-9-23 2:18:22 作者: JAVA题库 阅读次数:59 来源: http://www.d9soft.com
Question 59)
What will happen when you attempt to compile and run the following code
class Base{
private void amethod(int iBase){
System.out.println("Base.amethod");
}
}
class Over extends Base{
public static void main(String argv[]){
Over o = new Over();
int iBase=0;
o.amethod(iBase);
}
public void amethod(int iOver){
System.out.println("Over.amethod");
}
}
1) Compile time error complaining that Base.amethod is private
2) Runtime error complaining that Base.amethod is private
3) Output of "Base.amethod"
4) Output of "Over.amethod"
Answer to Question 59
--------------------------------------------------------------------------------
Question 60)
You are creating an applet with a Frame that contains buttons. You are using the GridBagLayout manager and you have added Four buttons. At the moment the buttons appear in the centre of the frame from left to right. You want them to appear one on top of the other going down the screen. What is the most appropriate way to do this.
1) Set the gridy value of the GridBagConstraints class to a value increasing from 1 to 4
2) set the fill value of the GridBagConstraints class to VERTICAL
3) Set the ipady value of the GridBagConstraints class to a value increasing from 0 to 4
4) Set the fill value of the GridBagLayouts class to GridBag.VERTICAL
Answer to Question 60
If you have a copy of the Roberts and Heller Java 2 Guide that says the exam does not cover the GridBagLayout, this is an error. You can confirm this by looking at the online errata at
http://www.sybex.com/cgi-bin/rd_err_temp.pl?2463err.html
--------------------------------------------------------------------------------
Answers
--------------------------------------------------------------------------------
Answer 1)
Back to question 1)
Objective 4.5)
5) int i=10;
explanation:
1) float f=1.3;
Will not compile because the default type of a number with a floating point component is a double. This would compile with a cast as in
float f=(float) 1.3
2) char c="a";
Will not compile because a char (16 bit unsigned integer) must be defined with single quotes. This would compile if it were in the form
char c='a';
3) byte b=257;
Will not compile because a byte is eight bits. Take of one bit for the sign component you can define numbers between
-128 to +127
4) a boolean value can either be true or false, null is not allowed
http://www.jchq.net/tutorial/04_05Tut.htm.
--------------------------------------------------------------------------------
Answer 2)
Back to question 2)
Objective 4.1
1) Can't make static reference to void amethod.
Because main is defined as static you need to create an instance of the class in order to call any non-static methods. Thus a typical way to do this would be.
MyClass m=new MyClass();
m.amethod();
Answer 2 is an attempt to confuse because the convention is for a main method to be in the form
String argv[]
That argv is just a convention and any acceptable identifier for a string array can be used. Answers 3 and 4 are just nonsense.
http://www.jchq.net/tutorial/04_01Tut.htm
--------------------------------------------------------------------------------
Answer 3)
back to Question 3)
Objective 4.1)
2 and 3 will compile without error.
1 will not compile because any package declaration must come before any other code. Comments may appear anywhere
http://www.jchq.net/tutorial/04_01Tut.htm .
--------------------------------------------------------------------------------
Answer 4)
Back to question 4)
上一篇文章: SCJP Mock Exam 4(8) 下一篇文章: SCJP Mock Exam 4(10)
相关文章:
相关软件:

