电话:0731-83595998
导航

格林模拟试题三参考答案(4)

来源: 2017-12-19 10:54

 

answer to question 39)

4) the code will compile without error

there are no restrictions on the level of nesting for inner/nested classes. inner classes may be marked private. the main method is not declared as public static void main, and assuming that the commandline was java droitwich it would not be invoked anyway.

answer to question 40)

1) super.oak=1;
3) base.oak=22;

because the variable oak is declared as static only one copy of it will exist. thus it can be changed either through the name of its class or through the name of any instance of that class. because it is created as an integer it canot be assigned a fractional component without a cast.

 

 

answer to question 41)

obje question 41)

4) use the gettext method of a textfield and use the parseint method of the integer class

here is an example of how you might do this

integer.parseint(txtinputvalue.gettext());

i'm not sure that a question on this actually will come up in the exam but it is a very useful thing to know in the real world.

 

 

answer to question 42)

4) none of the above

the wrapper classes are immutable. once the value has been set it cannot be changed. a common use of the wrapper classes is to take advantage of their static methods such as integer.parseint(string s) that will returns an integer if the the value has been set it cannot be changed. a common use of the wrapper classes is to take advantage of their static methods such as integer.parseint(string s) that will returns an integer if the string contains one.

|||

answer to question 43)

2) constructors cannot be overriden

overloading constructors is a key technique to allow multiple ways of initialising classes. by definition, constructors have have no return values so option 3 makes no sense. option 4 is the inverse of what happens as constructor code will execute starting from the oldest ancestor class downwards. you can test this by writing a class that inherits from a base class and getting the constructor to print out a message. when you create the child class you will see the order of constructor calling.

 

answer to question 44)

yield is a static method and causes whatever thread is currently executing to yield its cycles.

1) t.yield();

(thanks roseanne )

answer to question 45)

4) compilation and run with an output of 99

the fact that the variable court is declared as private does not stop the constructor from being able to initialise it.

answer to question 46)

3) to be overriden a method must have the same name, parameter and return types

option 1 is a sneaky one in that it should read overriden not overloaded. an overriden method must also have the same return type. parameter names are purely a programmer convenience and are not a factor in either overloading and overriding. parameter order is a factor however.

answer to question 47)

1) compile time error

with the sun jdk it will produce the following error

"only constructors can invoke constructors".

if you took out the call to super that causes this error the program would compile and at runtime it would output base and then checket as constructors are called from the oldest ancestor class downwards.

|||

answer to question 48)

1) static methods cannot be overriden to be non static

the jdk1.1 compiler will issue an error message "static methods cannot be overriden" if you atempt to do thiuot; if you atempt to do this. there is no logic or atempt to do this. there is no logic or reason why private methods should not be overloaded or that static methods should not be declared private. option 4 is a jumbled up version of the limitations of exceptions for overriden methods

answer to question 49)

2) a program can suggest that garbage collection be performed but not force it

if a program keeps creating new references without any being discarded it may run out of memory. unlike most aspects of java garbage collection is platform dependent.

 

answer to question 55)

1) compile time error

this might be considered a "gocha" or deliberate attempt to mislead you because i has been given the data type of long and the parameter must be of long and the parameter must be either a byte, char, short or int. if you attempt to compile this code with jdk 1.2 you will get an error that says something like "incompatible type for switch, explicit cast needed to convert long to int". answering with option 2 would have been reasonable because if the parameter had been an integer type the lack of break statements would have caused this output. if you gave either of the answers you should probably revise the subject.

answer to question 56)

1) system.out.println(i++); 
4) system.out.println(i==);

the options for this question might look suspiciously easy if you are not aware of the effects of the post-increment operators. the ++ and == operations for examples 1 and 4 only come into effect after the output operations, ie after whatever else is done to them on that line of code. option 2 should be fairly obvious as you should know that the single quote characters indicate a char value, ie storing the character rather than the numberical value for 0.

answer to question 57)

4) system.out.println( ((agg) a).getfields());

the base type reference to the instance of the class agg needs to be cast from base to agg to get access to its methods.the method invoked depends on the object itself, not on the declared type. so, a.getfield() tries to invoke a getfield method in base which does not exist. but the call to ((agg)a).getfield() will invoke the getfield() in the agg class. you will be unlucky to get a question as complex as this on the exam. if you think option 1 is valid, have a go at compiling the code.

answer to question 58)

2) compilation and output of false

a variable defined at class level will always be given a default value and the default value for the primitive type boolean is false

answer to question 59)

1) the x,y coordinates of an instance of mouseevent can be obtained using the getx() and gety() methods

if you chose option 4, referring to the mythical gettime method you have made a reasonable guess based on the normal conventions of java. however the conventions do not always hold true. if you chose option 3 perhaps you are not as aware of the conventions as you should be.

answer to question 60)

2) the program will run and output only "fliton"

this question tests your knowledge of the principle that the finally clause will almost always run.

编辑推荐:

下载Word文档

温馨提示:因考试政策、内容不断变化与调整,长理培训网站提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准! (责任编辑:长理培训)

网络课程 新人注册送三重礼

已有 22658 名学员学习以下课程通过考试

网友评论(共0条评论)

请自觉遵守互联网相关政策法规,评论内容只代表网友观点!

最新评论

点击加载更多评论>>

精品课程

更多
10781人学习

免费试听更多

相关推荐
图书更多+
  • 电网书籍
  • 财会书籍
  • 其它工学书籍
拼团课程更多+
  • 电气拼团课程
  • 财会拼团课程
  • 其它工学拼团
热门排行

长理培训客户端 资讯,试题,视频一手掌握

去 App Store 免费下载 iOS 客户端