class TestA {  public void start() { System.out.println(”TestA”); }  }  public class TestB extends TestA {  public void start() { System.out.println(”TestB”); } public static void main(String[] args) {  ((TestA)new TestB()).start();  }  }  What is the re

题目

class TestA {  public void start() { System.out.println(”TestA”); }  }  public class TestB extends TestA {  public void start() { System.out.println(”TestB”); } public static void main(String[] args) {  ((TestA)new TestB()).start();  }  }  What is the result?() 

  • A、 TestA
  • B、 TestB
  • C、 Compilation fails.
  • D、 An exception is thrown at runtime.

相似考题
更多“class TestA {  public void start() { System.out.println(”TestA”); }  }  public class TestB extends TestA {  public void start() { System.out.println(”TestB”); } public static void main(String[] args) {  ((TestA)new TestB()).start();  }  }  What is the res”相关问题
  • 第1题:

    classTestA{publicvoidstart(){System.out.println(”TestA”);}}publicclassTestBextendsTestA{publicvoidstart(){System.out.println(”TestB”);}publicstaticvoidmain(String[]args){((TestA)newTestB()).start();}}Whatistheresult?()

    A.TestA

    B.TestB

    C.Compilationfails.

    D.Anexceptionisthrownatruntime.


    参考答案:B

  • 第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题:

    阅读下面程序 public class Test2 ______ { public static void main(String[] args) { Thread t=new Test2(); t.start(); } public void run() { System.out.println("How are you."); } } 程序中下画线处应填入的正确选项是

    A.implements Thread

    B.extends Runnable

    C.implements Runnable

    D.extends Thread


    正确答案:D

  • 第4题:

    class MyThread extends Thread {  public void run() { System.out.println(“AAA”); }  public void run(Runnable r) { System.out.println(“BBB”); }  public static void main(String[] args) {  new Thread(new MyThread()).start();  }  }   What is the result?()  

    • A、 AAA
    • B、 BBB
    • C、 Compilation fails.
    • D、 The code runs with no output.

    正确答案:A

  • 第5题:

    class A {  public A() {  System.out.println(“hello from a”);  }  }  class B extends A {  public B () {  System.out.println(“hello from b”);  super();  }  }  public class Test {  public static void main(String args[]) {  A a = new B();  }  }   What is the result when main is executed?()  

    • A、 Compilation fails.
    • B、 hello from a
    • C、 hello from b
    • D、 hello from b hello from a
    • E、 hello from a hello from b

    正确答案:A

  • 第6题:

    public class A extends Thread {  A() {  setDaemon(true);  }  public void run() {  (new B()).start();  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“A done”);  }  class B extends Thread {  public void run() {  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“B done”);  }  }  public static void main(String[] args) {  (new A()).start();  }  }   What is the result?()  

    • A、 A done
    • B、 B done
    • C、 A done B done
    • D、 B done A done
    • E、 There is no exception that the application will print anything.
    • F、 The application outputs “A done” and “B done”, in no guaranteed order.

    正确答案:B

  • 第7题:

    现有:      class TestA  {  public void start()  {  System.out.println("TestA");  }     }  public class TestB extends TestA  {  public void start()  {  System.out.println("TestB");  }     public static void main (string[]  args)  (     ((TestA)new TestB()).start();     )     }  运行结果是哪项?()     

    • A、  TeStA
    • B、  TeStB
    • C、编译失败
    • D、运行时抛出异常

    正确答案:B

  • 第8题:

    public class Starter extends Thread {  private int x= 2;  public static void main(String[] args) throws Exception {  new Starter().makeItSo();  }  public Starter() {  x=5;  start();  }  public void makeItSo() throws Exception {  join();  x=x- 1;  System.out.println(x);  }  public void run() { x *= 2; }  }  What is the output if the main() method is rum?() 

    • A、 4
    • B、 5
    • C、 8
    • D、 9
    • E、 Compilation fails.
    • F、 An exception is thrown at runtime.
    • G、 It is impossible to determine for certain.

    正确答案:D

  • 第9题:

    单选题
    class MyThread extends Thread {  public void run() { System.out.println(“AAA”); }  public void run(Runnable r) { System.out.println(“BBB”); }  public static void main(String[] args) {  new Thread(new MyThread()).start();  }  }   What is the result?()
    A

     AAA

    B

     BBB

    C

     Compilation fails.

    D

     The code runs with no output.


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

  • 第10题:

    单选题
    public class TestA{   public void methodA()  throws IOException{   //……   }   }   public class TestB extends TestA{   public void methodA()  throws EOFException{   //……   }   }   public class TestC extends TestA{   public void methodA()  throws Exception{   //……   }   }   当编译类TestC的时候,结果是哪项?()
    A

     正常

    B

     编译错误

    C

     运行错误

    D

     以上都不对


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

  • 第11题:

    单选题
    现有:      class TestA  {  public void start()  {  System.out.println("TestA");  }     }  public class TestB extends TestA  {  public void start()  {  System.out.println("TestB");  }     public static void main (string[]  args)  (     ((TestA)new TestB()).start();     )     }  运行结果是哪项?()
    A

      TeStA

    B

      TeStB

    C

    编译失败

    D

    运行时抛出异常


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

  • 第12题:

    单选题
    public class A extends Thread {  A() {  setDaemon(true);  }  public void run() {  (new B()).start();  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“A done”);  }  class B extends Thread {  public void run() {  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“B done”);  }  }  public static void main(String[] args) {  (new A()).start();  }  }   What is the result?()
    A

     A done

    B

     B done

    C

     A done B done

    D

     B done A done

    E

     There is no exception that the application will print anything.

    F

     The application outputs “A done” and “B done”, in no guaranteed order.


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

  • 第13题:

    在下面程序的下画线处应填入的选项是 public class Test______{ public static void main(String args[]) { Test t=new Test(); Thread tt=new Thread(t); tt.start(); } public void run() { for(int i=0;i<5;i++) System.out.println("i="+i); } }

    A.implements Runnable

    B.extends Thread

    C.implements Thread

    D.extends Runnable


    正确答案:A
    解析:创建线程有两种方法:实现java.lang.Runnahle接口和继承Thread类并重写run()方法。从创建线程实例的语句Thread tt=new Thread(t);可以看出本程序将Test类的实例t作为参数传递给Thread类的构造方法,因此是通过实现Runnable接口创建线程。

  • 第14题:

    使下列程序正常运行并且输出“Hello!”,横线处应填写的内容是( )。 class Test { public static void main(string[]args){ Test t=new Test; start; } Public void run{ System.out.println("Hello!¨); )

    A.extends Thread

    B.extends Float

    C.extends Iostream

    D.extends Stdio


    正确答案:A
    A。【解析】从后面重写了run方法来看,这是通过继承Thread类,并重写run方法定义线程体,然后创建该子类的对象的方式来创建线程。

  • 第15题:

    ( 30 )在程序的下划线处应填入的选项是

    public class Test _________{

    public static void main(String args[]){

    Test t = new Test();

    Thread tt = new Thread(t);

    tt.start();

    }

    public void run(){

    for(int i=0;i<5;i++){

    system.out.println( " i= " +i);

    }

    }

    }

    A ) implements Runnable

    B ) extends Thread

    C ) implements Thread

    D ) extends Runnable


    正确答案:A

  • 第16题:

    1. class TestA {  2. TestB b;  3. TestA() {  4. b = new TestB(this);  5. }  6. }  7. class TestB {  8. TestA a;  9. TestB(TestA a) {  10. this.a = a;  11. }  12. }  13. class TestAll {  14. public static void main (String args[]) {  15. new TestAll().makeThings(); 16. // ...code continues on  17. }  18. void makeThings() {  19. TestA test = new TestA(); 20. }  21. }  Which two statements are true after line 15, before main completes?()

    • A、 Line 15 causes a stack overflow.
    • B、 An exception is thrown at runtime.
    • C、 The object referenced by a is eligible for garbage collection.
    • D、 The object referenced by b is eligible for garbage collection.
    • E、 The object referenced by a is not eligible for garbage collection.
    • F、 The object referenced by b is not eligible for garbage collection.

    正确答案:C,D

  • 第17题:

    class Super {  public int i = 0;  public Super(String text) {  i = 1; }  }  public class Sub extends Super {  public Sub(String text) {  i = 2;  }   public static void main(String args[]) {  Sub sub = new Sub(“Hello”);  System.out.println(sub.i);  }  }  What is the result?()  

    • A、 0
    • B、 1
    • C、 2
    • D、 Compilation fails.

    正确答案:C

  • 第18题:

    Public class test (  Public static void stringReplace (String text)  (  Text = text.replace (‘j’ , ‘i’);  )  public static void bufferReplace (StringBuffer text)  (  text = text.append (“C”)  )   public static void main (String args[]}  (  String textString = new String (“java”); StringBuffer text BufferString = new StringBuffer (“java”);  stringReplace (textString);  bufferReplace (textBuffer);  System.out.printLn (textString + textBuffer);  ) )  What is the output?()


    正确答案:javajavaC

  • 第19题:

    public class TestA{   public void methodA()  throws IOException{   //……   }   }   public class TestB extends TestA{   public void methodA()  throws EOFException{   //……   }   }   public class TestC extends TestA{   public void methodA()  throws Exception{   //……   }   }   当编译类TestC的时候,结果是哪项?() 

    • A、 正常
    • B、 编译错误
    • C、 运行错误
    • D、 以上都不对

    正确答案:B

  • 第20题:

    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

  • 第21题:

    单选题
    public class Starter extends Thread {  private int x= 2;  public static void main(String[] args) throws Exception {  new Starter().makeItSo();  }  public Starter() {  x=5;  start();  }  public void makeItSo() throws Exception {  join();  x=x- 1;  System.out.println(x);  }  public void run() { x *= 2; }  }  What is the output if the main() method is rum?()
    A

     4

    B

     5

    C

     8

    D

     9

    E

     Compilation fails.

    F

     An exception is thrown at runtime.

    G

     It is impossible to determine for certain.


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

  • 第22题:

    单选题
    class TestA {  public void start() { System.out.println(”TestA”); }  }  public class TestB extends TestA {  public void start() { System.out.println(”TestB”); } public static void main(String[] args) {  ((TestA)new TestB()).start();  }  }  What is the result?()
    A

     TestA

    B

     TestB

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


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

  • 第23题:

    多选题
    1. class TestA {  2. TestB b;  3. TestA() {  4. b = new TestB(this);  5. }  6. }  7. class TestB {  8. TestA a;  9. TestB(TestA a) {  10. this.a = a;  11. }  12. }  13. class TestAll {  14. public static void main (String args[]) {  15. new TestAll().makeThings(); 16. // ...code continues on  17. }  18. void makeThings() {  19. TestA test = new TestA(); 20. }  21. }  Which two statements are true after line 15, before main completes?()
    A

    Line 15 causes a stack overflow.

    B

    An exception is thrown at runtime.

    C

    The object referenced by a is eligible for garbage collection.

    D

    The object referenced by b is eligible for garbage collection.

    E

    The object referenced by a is not eligible for garbage collection.

    F

    The object referenced by b is not eligible for garbage collection.


    正确答案: C,F
    解析: This is a typical example of the island of isolation. On line 15, the two objects TestA and TestB have a reference to one an other. Therefore, the correct answers are C. and D. A key point to remember is that an object that is referenced by another object can be eligible for garbage collection if the two objects form an island of isolated objects.