编译运行下面的程序,结果是什么? public class A { public static void main(String[] args) { B b = new B(); b.test(); } void test() { System.out.print("A"); } } class B extends A { void test() { super.test(); System.out.print("B"); } }A.产生编译错误B.代码可以编译运行,并输出结果ABC.代码可以编译运行,但

题目

编译运行下面的程序,结果是什么? public class A { public static void main(String[] args) { B b = new B(); b.test(); } void test() { System.out.print("A"); } } class B extends A { void test() { super.test(); System.out.print("B"); } }

A.产生编译错误

B.代码可以编译运行,并输出结果AB

C.代码可以编译运行,但没有输出

D.编译没有错误,但会产生运行时异常


相似考题
更多“编译运行下面的程序,结果是什么? public class A { public static void main(String[] args) { B b = new B(); b.test(); } void test() { System.out.print("A"); } } class B extends A { void test() { super.test(); System.out.print("B"); } }”相关问题
  • 第1题:

    下面程序的输出结果是什么? class C1{ static int j=0; public void method(int a){ j++; } } class Test extends C1{ public int method(){ return j++; } public void result(){ method(j); System.out.println(j+method()); } public static void main(String args[]){ new Te

    A.0

    B.1

    C.2

    D.3


    正确答案:C

  • 第2题:

    如下两个源程序文件,分别编译后,运行Example.class文件,运行结果为______。

    AB.java文件代码如下;

    package test;

    public class AB

    {

    int a=60;

    public void show()

    {

    System.out.println(”a=”+a);

    }

    Example.java文件代码如下:

    import test.AB;

    class Example

    {

    public static void main(String args[])

    {

    AB bj=new AB();

    obj.show();

    }

    }


    正确答案:a=60
    a=60

  • 第3题:

    在下面程序的下画线处应填入的选项是 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接口创建线程。

  • 第4题:

    使下列程序正常运行并且输出“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方法定义线程体,然后创建该子类的对象的方式来创建线程。

  • 第5题:

    阅读下列代码 public class Test2005{ public static void main(String args[]){ String s="Test"; switch(s){ case"Java":System.out.print("Java"); break; case"Language":System.out.print("Lan- guage"); break; case"Test":System.out.print("Test"); break; } } } 其运行结果是( )。

    A.Java

    B.Language

    C.Test

    D.编译时出错


    正确答案:D
    D。【解析】本题考查switch语句的用法。switch语句是多分支语句,即根据表达式的值来执行多个操作中的一个。在switch语句中,”表达式”的返回值类型必须是这几种类型之一:int、byte、char、short。本题中,switch的表达式s是一个字符串Strin9类型的值,它不是int、byte、char、short中的任意一个。因此表达式s的类型不对,编译时出错。

  • 第6题:

    下列程序的输出结果是 ( ) class Derao { void test() { Systeme.out.print("NO");} void test (int i) {System.out.print(a);} void test(int a,int b) {System.out.print(a+b);} } class Test { public static void main(String args[]) { Demo de=new Demo(); de.test(); de.test5.; de.test(6,8); } }

    A.No568

    B.568No

    C.No514

    D.86No5


    正确答案:C

  • 第7题:

    以下程序调试结果为:class Base{Base(){int i = 100;System.out.print (i);}}public class Pri extends Base{static int i = 200;public static void main(String argv[]){Pri p = new Pri();System.out.print(i);}}

    A.编译错误

    B.200

    C.100200

    D.100


    正确答案:C

  • 第8题:

    ( 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

  • 第9题:

    现有:  class Bird {  void talk() { System.out.print("chirp "); }         }  class Parrot2 extends Bird {  protected void talk() { System.out.print("hello ");        public static void main(String [] args) {  Bird [] birds = {new Bird(), new Parrot2 () };         for( Bird b : birds)          b.talk () ;         }         }  结果是什么 ?()      

    • A、 chirp chirp
    • B、 hello hello
    • C、 chirp hello
    • D、编译错误

    正确答案:C

  • 第10题:

    单选题
    class Beverage {   Beverage() { System.out.print("beverage "); }   }   class Beer extends Beverage {   public static void main(String [] args) {   Beer b = new Beer(14);   }   public int Beer(int x) {   this();   System.out.print("beer1 ");   }   public Beer() { System.out.print("beer2 "); }  }   结果是什么?()
    A

    beer1 beverage

    B

    beer2 beverage

    C

    beverage beer1

    D

    编译失败


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

  • 第11题:

    单选题
    现有  class Beverage {  Beverage ()  {  System.out.print ("beverage ");  }        }  class Beer extends Beverage {  public static void main{string [] args) {        Beer b = new Beer (14) ;       }  public int Beer(int x) {       this () ;  System.out.print ("beerl") ;      }  public Beer() { System.out.print("beer2 "); }     }  结果是什么?()
    A

    beerl beverage

    B

    beer2 beverage

    C

    beverage beer2 beerl

    D

    编译失败


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

  • 第12题:

    单选题
    现有:  class Bird {  void talk() { System.out.print("chirp "); }         }  class Parrot2 extends Bird {  protected void talk() { System.out.print("hello ");        public static void main(String [] args) {  Bird [] birds = {new Bird(), new Parrot2 () };         for( Bird b : birds)          b.talk () ;         }         }  结果是什么 ?()
    A

     chirp chirp

    B

     hello hello

    C

     chirp hello

    D

    编译错误


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

  • 第13题:

    下列程序的执行结果是 ( ) public class Test { public int aMethod() { satic int i=0; i++; System.out.println(i); } public static void.main(String args[]) { Test test=new Test(); test.aMethod(); }

    A.编译错误

    B.0

    C.1

    D.运行成功,但不输出


    正确答案:A

  • 第14题:

    执行下面程序后输出的正确结果是( )。 public class Test{ public static void main(String args[]){ System.out.print(100%3); System.out.print(","); System.out.print(100%0); } }

    A.1,1

    B.1,1.0

    C.1.0, l

    D.1.0,1.0


    正确答案:B

  • 第15题:

    阅读下列代码 public class Test { public static void main(String args[]) { String s = "Test"; switch (s) { case "Java": System.out.print("Java"); break; case "Language": System.out.print("Language"); break; case "Test": System.out.print("Test"); break; } } } 其运行结果是( )。

    A.Java

    B.Language

    C.Test

    D.编译出错


    正确答案:D
    解析:switch语句根据其后表达式的值从多个分支中选择一个来执行,表达式只能返回int、byte、short和char类型。

  • 第16题:

    指出下列程序运行的结果 ( ) public class Example{ String str=new String("good"); char[]ch={'a','b','c'}; public static void main(String args[]){ Example ex=new Example(); ex.change(ex.otr,ex.ch); System.out.print(ex.str+"and"); System.out.print(ex.ch); } public void change(String str,char ch[])} str="test ok"; ch[0]≈'g'; } }

    A.good and abc

    B.good and gbc

    C.test ok and abc

    D.test ok and gbc


    正确答案:B

  • 第17题:

    下列程序的输出结果是 class Demo { void test( ) { Systeme.out.pnnt("NO");} void test(int i) { System.out.print(a);} void test(int a,int b) { System.out.print(a+b);} } class Test { public static void main(String args[ ] ) { Demo de=new Demo( ); de.test( ); de.test(5); de.test(6,8); } }

    A.No 5 6 8

    B.5 6 8 No

    C.No 5 14

    D.8 6 No 5


    正确答案:C
    解析:本题考查的是方法重载的概念及应用,本题中应顺调查用test(),test(5)和test(6,8)方法,所以答案为选项C)。

  • 第18题:

    以下程序调试结果为:

    public class Test {

    int m=5;

    public void some(int x) {

    m=x;

    }

    public static void main(String args []) {

    new Demo().some(7);

    }

    }

    class Demo extends Test {

    int m=8;

    public void some(int x) {

    super.some(x);

    System.out.println(m);

    }

    }

    A.5

    B.8

    C.7

    D.无任何输出

    E.编译错误


    正确答案:B

  • 第19题:

    下列程序运行的结果为:

    public class Example{

    String str=new String("good");

    char[] ch={'a','b','c'};

    public static void main(String args[]){

    Example ex=new Example();

    ex.change(ex.str,ex.ch);

    System.out.print(ex.str+" and ");

    Sytem.out.print(ex.ch);

    }

    public void change(String str,char ch[]){

    str="test ok";

    ch[0]='g';

    }

    }

    A. good and abc

    B. good and gbc

    C. test ok and abc

    D. test ok and gbc


    正确答案:B

  • 第20题:

    class BitStuff {   BitStuff go() { System.out.print("bits "); return this; }   }   class MoreBits extends BitStuff {   MoreBits go() { System.out.print("more "); return this; }   public static void main(String [] args) {   BitStuff [] bs = {new BitStuff(), new MoreBits()};   for( BitStuff b : bs)   b.go();   }   }   结果为:()  

    • A、bits bits
    • B、bits more
    • C、more more
    • D、编译失败

    正确答案:B

  • 第21题:

    现有:      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

  • 第22题:

    单选题
    class ThreadBoth extends Thread implements Runnable {  public void run(){ System.out.print("hi "); }  public static void main(String [] args){  Thread t1 = new ThreadBoth();   Thread t2 = new Thread(t1);  t1.run();  t2.run();  }  }  结果为:()
    A

    hi

    B

    hi hi

    C

    编译失败

    D

    代码运行,但无输出结果


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

  • 第23题:

    单选题
    class Bird {  static void talk() { System.out.print("chirp "); }  }  class Parrot extends Bird {  static void talk() { System.out.print("hello "); }  public static void main(String [] args) {  Bird [] birds = {new Bird(), new Parrot()};  for( Bird b : birds)  b.talk();  }  }  结果为:()
    A

    chirp chirp

    B

    chirp hello

    C

    hello hello

    D

    编译失败


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

  • 第24题:

    单选题
    下列程序的运行结果是(  )。class Shape{ public Shape(){ System.out.print("Shape"); }}class Circle extends Shape{ public Circle(){ System.out.print("Circle"); }}public class Test{ public static void main(String[]args){ Shape d=new Circle(); }}
    A

    Shape

    B

    Circle

    C

    ShapeCircle

    D

    程序有错误


    正确答案: B
    解析:
    继承是面向对象编程的一个主要优点之一,它对如何设计Java类有着直接的影响。该程序首先编写了一个Shape的类,然后又编写一个类Circle去继承Shape类。由于子类拥有父类所有的属性和方法,所以输出的是ShapeCircle。