public void add(C c) { c.getValue(); }
public void add(B b) { b.getValue(); }
public void add(A a) { a.getValue(); }
public void add(A a, B b) { a.getValue(); }
public void add(C c1, C c2) { c1.getValue(); }
第1题:
A.class B implements A{ int method1(){} int method2(){} }
B.class B { int method1(int i){} int method2(int j){} }
C.class B implements A{ int method1(int i){} int method2(int j){} }
D.class B extends A{ int method1(int i){} int method2(int j){} }
第2题:
interface A{
int x = 0;
}
class B{
int x =1;
}
class C extends B implements A {
public void pX(){
System.out.println(x);
}
public static void main(String[] args) {
new C().pX();
}
}
错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的
x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。
对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可
以通过A.x 来明确。
第3题:
下列关于Test类的定义中,正确的是______。
A) class Test implements Runnabte{
public void run(){}
public void someMethod(){}
B) class Test implements Rnuuable{
public void run();
}
C) class Test implements Rnuuable{
public void someMethod();
}
D) class Test implements Rnuuable{
public void someMethod();{}
}
A.
B.
C.
D.
第4题:
interface DeclareStuff{ public static final int EASY = 3; void doStuff(int t); } public class TestDeclare implements DeclareStuff { public static void main(String [] args) { int x=5; new TestDeclare().doStuff(++x); } void doStuff(int s) { s += EASY + ++s; System.out.println(”s “ + s); } } What is the result?()
第5题:
有一个接口定义如下,下列选项中实现了该接口并且不是抽象的是( )。interface A{ int method1 (int i); int method2 (int j);}
A.class B implements A{ int method1() { } int method2() { }}
B.class B{int method1(int i) { }int method2(int j) { }}
C.class B implements A{ int methodl(int i) { } int method2(intj) { }}
D.class B extends A{int method1(int i) { }int method2(int j) { }}
第6题:
下列程序的输出结果是 interface Inter{ public final static int A=100; } class My implements Inter{ public static void main (String args[ ]) {System.out.println(A) ; }
A.100
B.0
C.A
D.程序有错误
第7题:
已知类SubClass的getSum方法返回其父类成员i与类SubClass成员j的和;类SuperClass中的getSum为抽象函数,程序中的第14行有错误,请修改该错误并给出修改后的完整结果,然后完善程序中的空缺,当程序运行到第22行且尚未执行第22行语句时成员变量i的值,最后给出程序运行后的输出结果。
[Java代码]
行号 代码
01 public class UainJava{
02 public static void main(String[]args){
03 SuperClass s=new SubClass();
04 System.out.printin(s.getValue());
05 System.out.printIn(s.getSum()):
06 }
07 }
08 abstract class SuperClass {
09 private int i;
10 public SuperClass(){i=5;}
11 public int getValue(){
12 return i:
13 }
14 public final abstract int getSum():
15 }
16 class SubClass extends SuperClass{
17 int j;
18 public SubClass(){
19 this(-3);
20 }
21 public SubClass(int j){
22 (1) .j=j;
23 }
24 publiC int getValue()(return j;}
25 public int getSum(){
26 return (2) .getValue()+j;
27 }
28
第8题:
下列哪个方法可用于创建一个可运行的类? ( )
A.public class X implements Runable {public void run(){...,.,}}
B.public class X implements Thread {public void run(){......}}
C.public class X implements Thread {public int run(){……}}
D.public class X implements Runable {protected void run(){.....}}
第9题:
public class ClassA{ public int getValue(){ int value=0; boolean setting=true; String title="Hello"; if(value||(setting && title=="Hello")){return 1;} if(value==1&title.equals("Hello")){return 2;} } } And: ClassA a=new ClassA(); a.getValue(); What is the result?()
第10题:
Which three demonstrate an “is a” relationship?()