无忧首页企业系统我的无忧
无忧服务:
兼职活动培训
娱乐交友:
交友社区资讯
全职实习:
实习暑假寒假
微信号:school51
扫一下,立即关注
加关注
在线支付,立省10元
下载新版APP
===大学生成长生活平台===

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

2012-12-26来源/作者:卫凯点击次数:626

 

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;
2) oak=33;
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();
2) thread.yield()

(thanks roseanne )
javadoc for the thread class


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
4) a reference becomes eligable for garbage collection when it is assigned to null

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++);
3) 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
4) the time of a mouseevent can be extracted using the getwhen method

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.





相关阅读



关于我们 | 联系我们 | 用户指南 | 网站地图 | 意见建议 | 会员注册 | 用户协议 | 隐私政策