单选题给定如下Java程序片断:  class A{  public A (){   System.out.println("A");  } }  class B extends A{  public B(){  System.out.println("B"); }  public static void main(String[] args){    B b=new B();  } }  上述程序将()。A 不能通过编译B 通过编译,输出为:A BC 通过编译,输出为:BD 通过编译,输出为:A

题目
单选题
给定如下Java程序片断:  class A{  public A (){   System.out.println("A");  } }  class B extends A{  public B(){  System.out.println("B"); }  public static void main(String[] args){    B b=new B();  } }  上述程序将()。
A

不能通过编译

B

通过编译,输出为:A B

C

通过编译,输出为:B

D

通过编译,输出为:A


相似考题
参考答案和解析
正确答案: C
解析: 暂无解析
更多“单选题给定如下Java程序片断:  class A{  public A (){   System.out.println("A");  } }  class B extends A{  public B(){  System.out.println("B"); }  public static void main(String[] args){    B b=new B();  } }  上述程序将()。A 不能通过编译B 通过编译,输出为:A BC 通过编译,输出为:BD 通过编译,输出为:A”相关问题
  • 第1题:

    给出下列的程序,其叙述正确的是public class Man { static int arr[]= new int [10]; public static void main (String a []){ System.out.println(arr[1]); }}

    A.编译时将发生错误

    B.编译时正确但是运行时出错

    C.输出为0

    D.输出为null


    正确答案:C
    解析:由于数组元素是整型,所以其初始值为0。

  • 第2题:

    给定如下JAVA程序片断下述程序将()。

    A.不能通过编译

    B.通过编译,输出为:AB

    C.通过编译,输出为:B

    D.通过编译,输出为:A


    正确答案:B

  • 第3题:

    2给出下列的程序,其叙述正确的是( )。public class Man{static int arr[]=new int[10];public static void main(String args[]){System.out.println (arr[1=];}}

    A.编译时将发生错误

    B.编译时正确但是运行时出错

    C.输出为0

    D.输出为null


    正确答案:C

  • 第4题:

    下面程序段的输出结果为 package test; public class Class A { int x=20; static int y=6; public static void main(String args[]) { Class B b=new Class B(); b.go(10); System.out.println("x"+b.x); } } class ClassB { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }

    A.x=10

    B.x-20

    C.x=6

    D.编译不通过


    正确答案:C
    解析:本题考查在Java中静态变量(类变量)的用法。在题目程序段中生成了一个staticinty=6类变量,在ClassA中调用的b.go(10),只不过是在ClassB中的一个局部变量,通过调用ClassB中的go方法可以生成一个ClassA对象,并给这个新生成的对象赋以ClassA中的类变量y的值。从main()方法作为入口执行程序,首先生成一个ClassB的对象,然后b.go(10)会调用ClassA,会给x和y赋值,x=a.y后,x值为6,再返回去执行System.out.println("x="+b.x)语句,输出为x=6,可见,正确答案为逸项C。

  • 第5题:

    以下程序的调试结果为?

    public class Outer{

    public String name = "Outer";

    public static void main(String argv[]){

    Inner i = new Inner();

    i.showName();

    }

    private class Inner{

    String name =new String("Inner");

    void showName(){

    System.out.println(name);

    }

    }

    }

    A.输出结果 Outer

    B.输出结果 Inner

    C.编译错误,因Inner类定义为私有访问

    D.在创建Inner类实例的行出现编译错误


    正确答案:D

  • 第6题:

    以下的程序的调试结果为?public class MyAr{public static void main(String argv[]) {MyAr m = new MyAr();m.amethod();}public void amethod(){static int i;System.out.println(i);}}

    A. 输出结果为 0

    B. 运行出错

    C. 输出结果为 null

    D. 编译错误


    正确答案:D

  • 第7题:

    以下的程序的调试结果为public class Scope{int i;public static void main(String argv[]){Scope s = new Scope();s.amethod();}public static void amethod(){System.out.println(i);}}

    A. 输出结果为:0

    B. 无输出

    C. 编译错误

    D. 输出null


    正确答案:C

  • 第8题:

    执行下面程序,输出的结果是?() public class Test{  public static void main(String[] args){  int a = 5;  double b = 8;  a = a++ + b;   System.out.println(a);  }  } 

    • A、 第4行编译报错
    • B、 第5行编译报错
    • C、 编译成功,输出13
    • D、 编译成功,输出14

    正确答案:B

  • 第9题:

    编译如下的Java程序片段:  Class test{     Int count=9;     Public void a(){   Int count=10;   System.out,println(“count 1=” + count); }  Public void count(){   System.out.println(“count 2 =”+ count); }  Public static void main(String args[] ){   Test t=new Test();   t.a();   t.count(); } }  结果是()

    • A、不能通过编译
    • B、输出:count 1 =10  count 2=9
    • C、输出:count 1=9 count 2=9

    正确答案:B

  • 第10题:

    单选题
    执行下面程序,输出的结果是?() public class Test{  public static void main(String[] args){  int a = 5;  double b = 8;  a = a++ + b;   System.out.println(a);  }  }
    A

     第4行编译报错

    B

     第5行编译报错

    C

     编译成功,输出13

    D

     编译成功,输出14


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

  • 第11题:

    单选题
    编译如下的Java程序片段:  Class test{     Int count=9;     Public void a(){   Int count=10;   System.out,println(“count 1=” + count); }  Public void count(){   System.out.println(“count 2 =”+ count); }  Public static void main(String args[] ){   Test t=new Test();   t.a();   t.count(); } }  结果是()
    A

    不能通过编译

    B

    输出:count 1 =10  count 2=9

    C

    输出:count 1=9 count 2=9


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

  • 第12题:

    单选题
    以下的程序的执行结果为? () public class Demo{  public double getHeight(){  return 171.0;  }  public int getHeight (){  return 171;  }  public static void main(String[] args){  Demo demo = new Demo();  System.out.println(demo.getHeight());  }  }
    A

    输出171.0

    B

    输出171

    C

    第2行和第5行编译报错

    D

    第10行编译报错


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

  • 第13题:

    下面程序段的输出结果为 package test; public class A { int x=20; static int y=6; public static void main(String args[]) { Class B b=new Class B(); b.go(10); System.out.println(”x=”+b.x); } } class Class B { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }

    A.x=10

    B.x=20

    C.x=6

    D.编译不通过


    正确答案:C
    解析:本题考查在Java中静态变量(类变量)的用法。在题目程序段中生成了一个staticinty=6类变量,在ClassA中调用的b.go(10),只不过是在ClassB中的一个局部变量,通过调用ClassB中的go方法可以生成一个ClassA对象,并给这个新生成的对象赋以ClassA中的类变量y的值。从main()方法作为入口执行程序,首先生成一个ClassB的对象,然后b.go(10)会调用ClassA,会给x和y赋值,x=a.y后,x值为6,再返回去执行System.out.println(”x=”+b.x)语句,输出为x=6,可见,正确答案为选项C。

  • 第14题:

    编译运行以下程序后,关于输出结果的说明正确的是( )。 public class Conditional{ public static void main (String args[]){ int x=2: System.out.println("value is”+ ((x<1)?2:2)); } }

    A.输出结果为:valueis22.2

    B.输出结果为:value is 2

    C.输出结果为:value is 2.0

    D.编译错误


    正确答案:C

  • 第15题:

    当你编译运行下列程序代码,会得到什么结果?

    private class Base{ Base(){ int i = 100; System.out.println(i); } }

    public class Pri extends Base{ staticint i = 200;

    public static void main(String argv[]){ Pri p = new Pri(); System.out.println(i); } }

    A.这段代码不能通过编译

    B.输出200

    C.输出100和200

    D.输出100


    正确答案:A

  • 第16题:

    类A及其派生类B定义如下:class A{ public int getInfo(int a) { return a; }}public class B extends A{ public float getInfo(int b) { return b; } public static void main(String[]args) { A a=new A(); B b=new B(); System.out.println(a.getInfo(3)+","+b.getInfo(5)); }}关于上述程序代码的叙述中正确的是 ( )

    A.第10行不能通过编译

    B.程序通过编译,输出结果为:3,3

    C.程序通过编译,输出结果为3,5

    D.程序通过编译,输出结果为:5,5


    正确答案:A
    解析:本题中,第10不能通过编译,因为getInfo定义的是float型,而里面的参数却是int型,再者,如果定义为float型也不能覆盖classA的方法。所以不正确,应该该为int型。

  • 第17题:

    以下程序调试结果为:

    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

  • 第18题:

    以下程序的编译和运行结果为?

    abstract class Base{

    abstract public void myfunc();

    public void another(){

    System.out.println("Another method");

    }

    }

    public class Abs extends Base{

    public static void main(String argv[]){

    Abs a = new Abs();

    A.amethod();

    }

    public void myfunc(){

    System.out.println("My Func");

    }

    public void amethod(){

    myfunc();

    }

    }

    A.输出结果为 My Func

    B.编译指示 Base 类中无抽象方法

    C.编译通过,但运行时指示Base 类中无抽象方法

    D.编译指示Base 类中的myfunc方法无方法体,没谁会喜欢该方法。


    正确答案:A

  • 第19题:

    以下的程序的执行结果为? () public class Demo{  public double getHeight(){  return 171.0;  }  public int getHeight (){  return 171;  }  public static void main(String[] args){  Demo demo = new Demo();  System.out.println(demo.getHeight());  }  } 

    • A、输出171.0
    • B、输出171
    • C、第2行和第5行编译报错
    • D、第10行编译报错

    正确答案:C

  • 第20题:

    给定如下Java程序片断:  class A{  public A (){   System.out.println("A");  } }  class B extends A{  public B(){  System.out.println("B"); }  public static void main(String[] args){    B b=new B();  } }  上述程序将()。 

    • A、不能通过编译
    • B、通过编译,输出为:A B
    • C、通过编译,输出为:B
    • D、通过编译,输出为:A

    正确答案:B

  • 第21题:

    编译如下Java程序片断:  class test{  int count = 9;  public void a(){    int count=10;  System.out.println("count 1 =" + count);  }  public void count(){  System.out.println("count 2 =" + count);  }  public static void main(String args[]){    test t=new test();    t.a();   t.count();   } }  结果将()。    

    • A、不能通过编译
    • B、输出:       count 1 = 10        count 2 = 9
    • C、输出:          count 1 = 9          count 2 = 9

    正确答案:B

  • 第22题:

    单选题
    下列程序的运行结果是(  )。class Test extends Thread{  public static void main(String[] args)  {    Thread t=new Thread();    t.start();  }  public void run()  {    System.out.println("Hello");  }}
    A

    程序不能通过编译,因为没有import语句将Thread类引入

    B

    程序不能通过编译,因为Test类没有实现Runnable接口

    C

    程序通过编译,且运行正常,没有任何输出

    D

    程序通过编译,且运行正常,打印出一个"Hello"


    正确答案: C
    解析:
    此程序继承了Thread,同时也有run方法,符合线程的创建规则,但是在创建线程对象时,所使用的的类为Thread,此处所创建对象毫无意义,不会运行任何结果,应该创建Test的对象,所以该程序会通过编译,且运行正常,但是没有任何输出。

  • 第23题:

    单选题
    编译如下Java程序片断:  class test{  int count = 9;  public void a(){    int count=10;  System.out.println("count 1 =" + count);  }  public void count(){  System.out.println("count 2 =" + count);  }  public static void main(String args[]){    test t=new test();    t.a();   t.count();   } }  结果将()。
    A

    不能通过编译

    B

    输出:       count 1 = 10        count 2 = 9

    C

    输出:          count 1 = 9          count 2 = 9


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

  • 第24题:

    单选题
    给定如下Java程序片断:  class A{  public A (){   System.out.println("A");  } }  class B extends A{  public B(){  System.out.println("B"); }  public static void main(String[] args){    B b=new B();  } }  上述程序将()。
    A

    不能通过编译

    B

    通过编译,输出为:A B

    C

    通过编译,输出为:B

    D

    通过编译,输出为:A


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