标签:except 考试题 pat put 对象 void fail ring this
QUESTION 73 Given:10: public class Hello {
11: String title;
12: int value;
13: public Hello() {
14: title += " World";
15: }
16: public Hello(int value) {
17: this.value = value;
18: title = "Hello";
19: Hello();
20: }
21: } and:
30: Hello c = new Hello(5); 31: System.out.println(c.title);
What is the result?
A. Hello
B. Hello World
C. Compilation fails.
D. Hello World 5
E. The code runs with no output.
F. An exception is thrown atruntime.
Answer: C
19行代码,不能这样使用,必须是this.Hello();如果直接使用,则必须是静态方法。
QUESTION 76
Given:
重写和重载。A是重写,C,E,F,G是重载。
QUESTION 77
Given:
public final void addTopping(String topping) 不允许重写。
java中当方法被final修饰就表示它是不可被子类重写的方法。
QUESTION 78
Given:
p2/p4引用的是C类型的对象,p1/p3引用的是B类型的对象,p0引用的是A类型的对象,而B和C是A的子类,根据语言规范,可以把子类对象赋给父类,A正确,B错误。
p4在编译器看来是A类型的,不能再没有类型转换的情况下将p2 = p4;,C错误。
EF类型转换正确!
QUESTION 80 Given:
package com.company.application;
public class MainClass {
public static voidmain(String[] args) {}
And MainClass exists in the/apps/com/company/application directory. Assume the CLASSPATH environmentvariable is set to "." (current directory). Which two java commandsentered at the command line will run MainClass? (Choose two.)
A. java MainClass if run from the/apps directory
B. javacom.company.application.MainClass if run from the /apps directory
C. java -classpath /appscom.company.application.MainClass if run from any directory
D. java -classpath . MainClass ifrun from the /apps/com/company/application directory
E. java -classpath/apps/com/company/application:. MainClass if run from the /apps directory
F. javacom.company.application.MainClass if run from the /apps/com/company/applicationdirectory
Answer: BC
Section: (none)
标签:except 考试题 pat put 对象 void fail ring this
原文地址:http://blog.51cto.com/2096101/2136773