OCJP视频课堂,具体讲解:https://edu.csdn.net/course/detail/7811
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:
1. public class Blip {
2. protected int blipvert(int x) { return 0; }
3. }
4. class Vert extends Blip {
5. // insert code here
6. }
Which five methods, inserted independently at line 5, will compile? (Choose five.)
A. public int blipvert(int x) { return 0; }
B. private int blipvert(int x) { return 0; }
C. private int blipvert(long x) { return 0; }
D. protected long blipvert(int x) { return 0; } 重载与返回类型无关
E. protected int blipvert(long x) { return 0; }
F. protected long blipvert(long x) { return 0; }
G. protected long blipvert(int x, int y) { return 0; }
Answer: A,C,E,F,G
重写和重载。A是重写,C,E,F,G是重载。
QUESTION 77public final void addTopping(String topping) 不允许重写。
java中当方法被final修饰就表示它是不可被子类重写的方法。
QUESTION 78
p2/p4引用的是C类型的对象,p1/p3引用的是B类型的对象,p0引用的是A类型的对象,而B和C是A的子类,根据语言规范,可以把子类对象赋给父类,A正确,B错误。
p4在编译器看来是A类型的,不能再没有类型转换的情况下将p2 = p4;,C错误。
EF类型转换正确!
QUESTION 80 Given:
1. package com.company.application;
2.
3. public class MainClass {
4. public static voidmain(String[] args) {}
5. }
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)