Compilation will succeed for all classes and interfaces.
Compilation of class C will fail because of an error in line 2.
Compilation of class C will fail because of an error in line 6.
Compilation of class AImpl will fail because of an error in line 2.
第1题:
interface Playable {
void play();
}
interface Bounceable {
void play();
}
interface Rollable extends Playable, Bounceable {
Ball ball = new Ball("PingPang");
}
class Ball implements Rollable {
private String name;
public String getName() {
return name;
}
public Ball(String name) {
this.name = name;
}
public void play() {
ball = new Ball("Football");
System.out.println(ball.getName());
}
}
这个错误不容易发现。
错。"interface Rollable extends Playable, Bounceable"没有问题。interface 可继承多个
interfaces,所以这里没错。问题出在interface Rollable 里的"Ball ball = new Ball("PingPang");"。
任何在interface 里声明的interface variable (接口变量,也可称成员变量),默认为public static
final。也就是说"Ball ball = new Ball("PingPang");"实际上是"public static final Ball ball = new
Ball("PingPang");"。在Ball 类的Play()方法中,"ball = new Ball("Football");"改变了ball 的
reference,而这里的ball 来自Rollable interface,Rollable interface 里的ball 是public static final
的,final 的object 是不能被改变reference 的。因此编译器将在"ball = new Ball("Football");"
这里显示有错。
第2题:
public class SomeException { } Class a: public class a { public void doSomething() { } } Class b: public class b extends a { public void doSomething() throws SomeException { } } Which is true about the two classes?()
第3题:
public interface A { String DEFAULT_GREETING = “Hello World”; public void method1(); } A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct?()
第4题:
Which declarations will allow a class to be started as a standalone program?()
第5题:
下列有关main()方法的签名正确的是哪些?()
第6题:
声明Java独立应用程序main()方法时,正确表达是()。
第7题:
下列代码正确的是哪项?()
第8题:
1. interface TestA { String toString(); } 2. public class Test { 3. public static void main(String[] args) { 4. System.out.println(new TestA() { 5. public String toString() { return “test”; } 6. } 7. } 8. } What is the result?()
第9题:
public class Employee implements Info extends Data { public void load(){/*dosomething*/} }
public class Employee extends Inf.implements Data{ public void load() {/*do something*/} }
public class Empl.yee implements Inf extends Data{ public void Data.1oad(){* do something*/} public void load(){/*do something*/} }
public class Employee extends Inf implements Data { public void Data.1oad() {/*do something*/) public void info.1oad(){/*do something*/} }
第10题:
Value is: 8
Compilation fails.
Value is: 12
Value is: -12
The code runs with no output.
An exception is thrown at runtime.
第11题:
Compilation fails because of an error in line 3.
Compilation fails because of an error in line 7.
Compilation fails because of an error in line 9.
If you define D e = new E(), then e.bMethod() invokes the version of bMethod()defined in Line 5.
If you define D e = (D)(new E()),then e.bMethod() invokes the version of bMethod() defined in Line 5.
If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.
第12题:
Cause error during compilation.
south east
south to north east to west
south to north east
south east to west
第13题:
A. public static void main();
B. public static void main( String args );
C. public static void main( String args[] );
D. public static void main( Graphics g );
E. public static boolean main( String a[] );
第14题:
以下是JAVA中正确的入口方法是? ()
第15题:
1. public interface A { 2. public void doSomething(String thing); 3. } 1. public class AImpl implements A { 2. public void doSomething(String msg) { } 3. } 1. public class B { 2. public A doit() { 3. // more code here 4. } 5. 6. public String execute() { 7. // more code here 8. } 9. } 1. public class C extends B { 2. public AImpl doit() { 3. // more code here 4. } 5. 6. public Object execute() { 7. // more code here 8. } 9. } Which statement is true about the classes and interfaces in the exhibit?()
第16题:
Which two allow the class Thing to be instantiated using new Thing()?
第17题:
作为Java应用程序入口的main方法,其声明格式可以是()。
第18题:
在J2EE中,以下是firePropertyChange的原型,正确的是()。
第19题:
现有: interface Data {public void load();} abstract class Info {public abstract void load();} 下列类定义中正确使用Data和Info的是哪项?()
第20题:
下面哪些main方法可用于程序执行()
第21题:
Compilation of both classes will fail.
Compilation of both classes will succeed.
Compilation of class a will fail. Compilation of class b will succeed.
Compilation of class a will fail. Compilation of class a will succeed.
第22题:
public static void main(String[] args){}
public static void main(String args){}
public void main(String[] args){}
public static int main(String[] args){}
第23题:
public interface B extends A {}
public interface B implements A {}
public interface B instanceOf A {}
public interface B inheritsFrom A {}
第24题:
0
1
2
3