public class Base {  public static final String FOO = “foo”;  public static void main(String[] args) {  Base b = new Base();  Sub s = new Sub();  System.out.print(Base.FOO);  System.out.print(Sub.FOO);  System.out.print(b.FOO);  System.out.print(s.FOO); 

题目

public class Base {  public static final String FOO = “foo”;  public static void main(String[] args) {  Base b = new Base();  Sub s = new Sub();  System.out.print(Base.FOO);  System.out.print(Sub.FOO);  System.out.print(b.FOO);  System.out.print(s.FOO);  System.out.print(((Base)s).FOO);  } }  class Sub extends Base {public static final String FOO=bar;}  What is the result?() 

  • A、 foofoofoofoofoo
  • B、 foobarfoobarbar
  • C、 foobarfoofoofoo
  • D、 foobarfoobarfoo
  • E、 barbarbarbarbar
  • F、 foofoofoobarbar
  • G、 foofoofoobarfoo

相似考题
更多“public class Base {  public static final String FOO = “foo”;  public static void main(String[] args) {  Base b = new Base();  Sub s = new Sub();  System.out.print(Base.FOO);  System.out.print(Sub.FOO);  System.out.print(b.FOO);  System.out.print(s.FOO);  ”相关问题
  • 第1题:

    class One {  public One() { System.out.print(1); }  }  class Two extends One {  public Two() { System.out.print(2); }  }  class Three extends Two {  public Three() { System.out.print(3); }  }  public class Numbers{  public static void main( String[] argv) { new Three(); }  }  What is the result when this code is executed?() 

    • A、 1
    • B、 3
    • C、 123
    • D、 321
    • E、 The code rims with no output.

    正确答案:C

  • 第2题:

    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、编译失败

    正确答案:A

  • 第3题:

    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”); }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }   public static void badMethod() {} }  What is the result?()  

    • A、 AC
    • B、 BD
    • C、 ACD
    • D、 ABCD
    • E、 Compilation fails.

    正确答案:C

  • 第4题:

    class Passer {  static final int x = 5;  public static void main(String [] args) { new Passer().go(x);  System.out.print(x);  }  void go(int x) {  System.out.print(++x);  }  }  结果是什么?() 

    • A、55
    • B、56
    • C、65
    • D、66

    正确答案:C

  • 第5题:

    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (RuntimeException ex) {  System.out.print(“B”);  }  catch (Exception ex1) {  System.out.print(“C”);  }   finally {  System.out.print(“D”);  }  System.out.print(“E”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result?()  

    • A、 BD
    • B、 BCD
    • C、 BDE
    • D、 BCDE
    • E、 ABCDE
    • F、 Compilation fails.

    正确答案:C

  • 第6题:

    class Birds {  public static void main(String [] args) {  try {  throw new Exception();  } catch (Exception e) { try {  throw new Exception();  } catch (Exception e2) { System.out.print("inner "); }  System.out.print("middle "); }  System.out.print("outer ");  }  }  结果为:()  

    • A、inner
    • B、inner outer
    • C、middle outer
    • D、inner middle outer

    正确答案:D

  • 第7题:

    public class Threads4 {  public static void main (String[] args) {  new Threads4().go();  }  public void go() {  Runnable r = new Runnable() { public void run() {  System.out.print(”foo”);  }  };  Thread t = new Thread(r);  t.start();  t.start();  }  }  What is the result?() 

    • A、 Compilation fails.
    • B、 An exception is thrown at runtime.
    • C、 The code executes normally and prints „foo”.
    • D、 The code executes normally, but nothing is printed.

    正确答案:B

  • 第8题:

    单选题
    public class Delta {  static boolean foo(char c) {  System.out.print(c);  return true;  }  public static void main( String[] argv ) {  int i =0;  for ( foo(‘A’); foo(‘B’)&&(i<2); foo(‘C’)){  i++ ;  foo(‘D’);  }  }  }  What is the result?()
    A

     ABDCBDCB

    B

     ABCDABCD

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


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

  • 第9题:

    单选题
    class Base {  Base() { System.out.print(“Base”); }  }  public class Alpha extends Base {  public static void main( String[] args ) {  new Alpha();  new Base();  }  }  What is the result?()
    A

     Base

    B

     BaseBase

    C

     Compilation fails.

    D

     The code runs with no output.

    E

     An exception is thrown at runtime.


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

  • 第10题:

    单选题
    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result? ()
    A

     AB

    B

     BC

    C

     ABC

    D

     BCD

    E

     Compilation fails.


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

  • 第11题:

    单选题
    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”); }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }   public static void badMethod() {} }  What is the result?()
    A

     AC

    B

     BD

    C

     ACD

    D

     ABCD

    E

     Compilation fails.


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

  • 第12题:

    单选题
    public class Base {  public static final String FOO = “foo”;  public static void main(String[] args) {  Base b = new Base();  Sub s = new Sub();  System.out.print(Base.FOO);  System.out.print(Sub.FOO);  System.out.print(b.FOO);  System.out.print(s.FOO);  System.out.print(((Base)s).FOO);  } }  class Sub extends Base {public static final String FOO=bar;}  What is the result?()
    A

     foofoofoofoofoo

    B

     foobarfoobarbar

    C

     foobarfoofoofoo

    D

     foobarfoobarfoo

    E

     barbarbarbarbar

    F

     foofoofoobarbar

    G

     foofoofoobarfoo


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

  • 第13题:

    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (Exception ex) {  System.out.print(“C”);  }  finally {  System.out.print(“B”);  }  System.out.print(“D”);  }  public static void badMethod() {  throw new Error();  }  }  What is the result?()  

    • A、 ABCD
    • B、 Compilation fails.
    • C、 C is printed before exiting with an error message.
    • D、 BC is printed before exiting with an error message.
    • E、 BCD is printed before exiting with an error message.

    正确答案:B

  • 第14题:

    class Foo {  private int x;  publicFoo(intx) {this.x=x; }  public void setX( int x) { this.x = x; }  public int getX() { return x; }  }   public class Gamma {  static Foo fooBar( Foo foo) {  foo = new Foo( 100);  return foo;  }  public static void main( String[] args) {  Foo foo = new Foo( 300);  System.out.print( foo.getX() + “-“);  Foo fooFoo = fooBar( foo);  System.out.print( foo.getX() + “-“);  System.out.print( fooFoo.getX() + “-“);  foo = fooBar( fooFoo);  System.out.print( foo.getX() + “-“);  System.out.prmt( fooFoo.getX());  }  }  What is the output of this program?()

    • A、 300-100-100-100-100
    • B、 300-300-100-100-100
    • C、 300-300-300-100-100
    • D、 300-300-300-300-100

    正确答案:B

  • 第15题:

    public class Delta {  static boolean foo(char c) {  System.out.print(c);  return true;  }  public static void main( String[] argv ) {  int i =0;  for ( foo(‘A’); foo(‘B’)&&(i<2); foo(‘C’)){  i++ ;  foo(‘D’);  }  }  }  What is the result?()  

    • A、 ABDCBDCB
    • B、 ABCDABCD
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:A

  • 第16题:

    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、编译失败

    正确答案:D

  • 第17题:

    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result? () 

    • A、 AB
    • B、 BC
    • C、 ABC
    • D、 BCD
    • E、 Compilation fails.

    正确答案:D

  • 第18题:

    class Base {  Base() { System.out.print(“Base”); }  }  public class Alpha extends Base {  public static void main( String[] args ) {  new Alpha();  new Base();  }  }  What is the result?()  

    • A、 Base
    • B、 BaseBase
    • C、 Compilation fails.
    • D、 The code runs with no output.
    • E、 An exception is thrown at runtime.

    正确答案:B

  • 第19题:

    单选题
    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (RuntimeException ex) {  System.out.print(“B”);  }  catch (Exception ex1) {  System.out.print(“C”);  }   finally {  System.out.print(“D”);  }  System.out.print(“E”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result?()
    A

     BD

    B

     BCD

    C

     BDE

    D

     BCDE

    E

     ABCDE

    F

     Compilation fails.


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

  • 第20题:

    单选题
    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (Exception ex) {  System.out.print(“C”);  }  finally {  System.out.print(“B”);  }  System.out.print(“D”);  }  public static void badMethod() {  throw new Error();  }  }  What is the result?()
    A

     ABCD

    B

     Compilation fails.

    C

     C is printed before exiting with an error message.

    D

     BC is printed before exiting with an error message.

    E

     BCD is printed before exiting with an error message.


    正确答案: E
    解析: The correct answer is : B is printed and then an error message is printed. The exception catch can not catch an Error because this class does not extend Exception but it implements throwable. 

  • 第21题:

    单选题
    public class Threads4 {  public static void main (String[] args) {  new Threads4().go();  }  public void go() {  Runnable r = new Runnable() { public void run() {  System.out.print(”foo”);  }  };  Thread t = new Thread(r);  t.start();  t.start();  }  }  What is the result?()
    A

     Compilation fails.

    B

     An exception is thrown at runtime.

    C

     The code executes normally and prints „foo”.

    D

     The code executes normally, but nothing is printed.


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

  • 第22题:

    单选题
    下列程序的运行结果是(  )。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。

  • 第23题:

    单选题
    class Passer {  static final int x = 5;  public static void main(String [] args) { new Passer().go(x);  System.out.print(x);  }  void go(int x) {  System.out.print(++x);  }  }  结果是什么?()
    A

    55

    B

    56

    C

    65

    D

    66


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