niusouti.com

单选题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 Strin

题目
单选题
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?()
A

 Compilation will succeed for all classes and interfaces.

B

 Compilation of class C will fail because of an error in line 2.

C

 Compilation of class C will fail because of an error in line 6.

D

 Compilation of class AImpl will fail because of an error in line 2.


相似考题
更多“1. public interface A {  2. public void doSomething(String t”相关问题
  • 第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?() 

    • A、 Compilation of both classes will fail.
    • B、 Compilation of both classes will succeed.
    • C、 Compilation of class a will fail. Compilation of class b will succeed.
    • D、 Compilation of class a will fail. Compilation of class a will succeed.

    正确答案:D

  • 第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?() 

    • A、 public interface B extends A {}
    • B、 public interface B implements A {}
    • C、 public interface B instanceOf A {}
    • D、 public interface B inheritsFrom A {}

    正确答案:A

  • 第4题:

    Which declarations will allow a class to be started as a standalone program?()  

    • A、public void main(String args[])
    • B、public void static main(String args[])
    • C、public static main(String[] argv)
    • D、final public static void main(String [] array)
    • E、public static void main(String args[])

    正确答案:D,E

  • 第5题:

    下列有关main()方法的签名正确的是哪些?()

    • A、 public static void main(String[] args){}
    • B、 public static void main(){}
    • C、 public static void main(String args[]){}
    • D、 public void static main(String[] args){}

    正确答案:A,C

  • 第6题:

    声明Java独立应用程序main()方法时,正确表达是()。

    • A、public static void main(String[]args){…}
    • B、private static void main(String args[]){…}
    • C、public void main(String args[]){…}
    • D、public static void main(){…}

    正确答案:A

  • 第7题:

    下列代码正确的是哪项?() 

    • A、 public class Session implements Runnable, Clonable{   public void run ();public Object clone () ; }
    • B、 public class Session extends Runnable, Cloneable {  public void run() {/*dosomething*/}       public Object clone() {/*make a copy*/} }
    • C、 public abstract class Session implements Runnable, Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}        }
    • D、 public class Session implements Runnable, implements Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}       }

    正确答案:C

  • 第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?() 

    • A、 test
    • B、 null
    • C、 An exception is thrown at runtime.
    • D、 Compilation fails because of an error in line 1.
    • E、 Compilation fails because of an error in line 4.
    • F、 Compilation fails because of an error in line 5.

    正确答案:A

  • 第9题:

    单选题
    现有:  interface Data {public void load();}  abstract class Info {public abstract void load();}      下列类定义中正确使用Data和Info的是哪项?()
    A

     public class Employee implements Info extends Data { public void load(){/*dosomething*/}     }

    B

    public class Employee extends Inf.implements Data{ public void load() {/*do something*/}     }

    C

    public class Empl.yee implements Inf extends Data{ public void Data.1oad(){* do something*/}     public void load(){/*do something*/}     }

    D

    public class Employee extends Inf implements Data  {  public void Data.1oad()  {/*do something*/)     public void info.1oad(){/*do something*/}    }


    正确答案: D
    解析: 暂无解析

  • 第10题:

    单选题
    1. public class SimpleCalc {  2. public int value;  3. public void calculate() { value += 7; }  4. } And:  1. public class MultiCalc extends SimpleCalc {  2. public void calculate() { value -= 3; }  3. public void calculate(int multiplier) {  4. calculate();  5. super.calculate();  6. value *=multiplier;  7. }  8. public static void main(String[] args) {  9. MultiCalc calculator = new MultiCalc();  10. calculator.calculate(2);  11. System.out.println(”Value is: “+ calculator.value);  12. }  13. }  What is the result?()
    A

     Value is: 8

    B

     Compilation fails.

    C

     Value is: 12

    D

     Value is: -12

    E

     The code runs with no output.

    F

     An exception is thrown at runtime.


    正确答案: A
    解析: 暂无解析

  • 第11题:

    单选题
    1. interface A { public void aMethod(); }  2. interface B { public void bMethod(); }  3. interface C extends A,B { public void cMethod(); }  4. class D implements B {  5. public void bMethod() { }  6. }  7. class E extends D implements C {  8. public void aMethod() { }  9. public void bMethod() { }  10. public void cMethod() { }  11. }  What is the result?()
    A

     Compilation fails because of an error in line 3.

    B

     Compilation fails because of an error in line 7.

    C

     Compilation fails because of an error in line 9.

    D

     If you define D e = new E(), then e.bMethod() invokes the version of bMethod()defined in Line 5.

    E

     If you define D e = (D)(new E()),then e.bMethod() invokes the version of bMethod() defined in Line 5.

    F

     If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.


    正确答案: E
    解析: 暂无解析

  • 第12题:

    单选题
    class Parent {     String one, two;  public Parent(String a, String b){     one = a;     two = b;    }  public void print(){ System.out.println(one); }    }  public class Child extends Parent {     public Child(String a, String b){     super(a,b);     }  public void print(){  System.out.println(one + " to " + two);     }  public static void main(String arg[]){     Parent p = new Parent("south", "north");     Parent t = new Child("east", "west");     p.print();     t.print();     }     }  Which of the following is correct?()
    A

     Cause error during compilation. 

    B

     south         east 

    C

     south to north     east to west    

    D

     south to north      east    

    E

     south     east to west


    正确答案: C
    解析: 这个题目涉及继承时的多态性问题,在前面的问题中已经有讲述,要注意的是语句t.print();在运行时t实际指向的是一个Child对象,即java在运行时决定变量的实际类型,而在编译时t是一个Parent对象,因此,如果子类Child中有父类中没有的方法,例如printAll(),那么不能使用t.printAll()。

  • 第13题:

    以下哪个是Java应用程序main方法的有效定义?

    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[] );


    正确答案:C

  • 第14题:

    以下是JAVA中正确的入口方法是? () 

    • A、 public static void main(String[] args){}
    • B、 public static void main(String args){}
    • C、 public void main(String[] args){}
    • D、 public static int main(String[] args){}

    正确答案:A

  • 第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?() 

    • A、 Compilation will succeed for all classes and interfaces.
    • B、 Compilation of class C will fail because of an error in line 2.
    • C、 Compilation of class C will fail because of an error in line 6.
    • D、 Compilation of class AImpl will fail because of an error in line 2.

    正确答案:C

  • 第16题:

    Which two allow the class Thing to be instantiated using new Thing()?

    • A、 public class Thing { }
    • B、 public class Thing { public Thing() {} }
    • C、 public class Thing { public Thing(void) {} }
    • D、 public class Thing { public Thing(String s) {} }
    • E、 public class Thing { public void Thing() {} public Thing(String s) {} }

    正确答案:A,B

  • 第17题:

    作为Java应用程序入口的main方法,其声明格式可以是()。

    • A、public static void main(String[] args)
    • B、public static int main(String[] args)
    • C、public void main(String[] args)
    • D、public int main(String[] args)

    正确答案:A

  • 第18题:

    在J2EE中,以下是firePropertyChange的原型,正确的是()。 

    • A、public void firePropertyChange(PropertyChangeListener l,String oldValue, String newValue)
    • B、public void firePropertyChange(String propertyName, Object oldValue, Object newValue)
    • C、public void firePropertyChange(PropertyChangeSupport changes)
    • D、public void firePropertyChange(Object oldValue, Object newValue)

    正确答案:B

  • 第19题:

    现有:  interface Data {public void load();}  abstract class Info {public abstract void load();}      下列类定义中正确使用Data和Info的是哪项?() 

    • A、 public class Employee implements Info extends Data { public void load(){/*dosomething*/}     }
    • B、public class Employee extends Inf.implements Data{ public void load() {/*do something*/}     }
    • C、public class Empl.yee implements Inf extends Data{ public void Data.1oad(){* do something*/}     public void load(){/*do something*/}     }
    • D、public class Employee extends Inf implements Data  {  public void Data.1oad()  {/*do something*/)     public void info.1oad(){/*do something*/}    }

    正确答案:B

  • 第20题:

    下面哪些main方法可用于程序执行()

    • A、public static void main(String[]args)
    • B、public static void main(String[]x)
    • C、public static void main(Stringargs[])
    • D、public void main(String[]args)

    正确答案:A,B,C

  • 第21题:

    单选题
    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?()
    A

     Compilation of both classes will fail.

    B

     Compilation of both classes will succeed.

    C

     Compilation of class a will fail. Compilation of class b will succeed.

    D

     Compilation of class a will fail. Compilation of class a will succeed.


    正确答案: B
    解析: 暂无解析

  • 第22题:

    单选题
    以下是JAVA中正确的入口方法是? ()
    A

     public static void main(String[] args){}

    B

     public static void main(String args){}

    C

     public void main(String[] args){}

    D

     public static int main(String[] args){}


    正确答案: D
    解析: 暂无解析

  • 第23题:

    单选题
    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?()
    A

     public interface B extends A {}

    B

     public interface B implements A {}

    C

     public interface B instanceOf A {}

    D

     public interface B inheritsFrom A {}


    正确答案: A
    解析: 暂无解析

  • 第24题:

    单选题
    1. interface Animal {   2. void eat();   3. }   4.   5. // insert code here   6.   7. public class HouseCat implements Feline {   8. public void eat() { }   9. }   和以下三个接口声明:   interface Feline extends Animal { }   interface Feline extends Animal { void eat(); }   interface Feline extends Animal { void eat() { } }   分别插入到第 5 行,有多少行可以编译?()
    A

    0

    B

    1

    C

    2

    D

    3


    正确答案: C
    解析: 暂无解析