单选题public class Test {   public static void main (String args) {   class Foo {   public int i = 3;  }   Object o = (Object) new Foo();   Foo foo = (Foo)o;   System.out.printIn(foo. i);  }   }   What is the result?()A Compilation will fail.B Compilation will succeed and the program will print “3”C Compilation will succeed but the program will throw a ClassCastException at line 6.D Compilation will succeed but the program will throw a ClassCastException at line 7.

单选题
public class Test {   public static void main (String args) {   class Foo {   public int i = 3;  }   Object o = (Object) new Foo();   Foo foo = (Foo)o;   System.out.printIn(foo. i);  }   }   What is the result?()
A

 Compilation will fail.

B

 Compilation will succeed and the program will print “3”

C

 Compilation will succeed but the program will throw a ClassCastException at line 6.

D

 Compilation will succeed but the program will throw a ClassCastException at line 7.


参考解析

解析: 暂无解析

相关考题:

public class Foo implements Runnable (  public void run (Thread t) {  system.out.printIn(“Running.”);  }  public static void main (String[] args)  {  new thread (new Foo()).start();  } )   What is the result?()      A、 An exception is thrown.B、 The program exists without printing anything.C、 An error at line 1 causes compilation to fail.D、 An error at line 2 causes the compilation to fail.E、 “Running” is printed and the program exits.

public class test(  public static void main(string[]args){  string foo = args [1];  string foo = args [2];  string foo = args [3];  }  )  And command line invocation: Java Test red green blue   What is the result?()  A、 Baz has the value of “”B、 Baz has the value of nullC、 Baz has the value of “red”D、 Baz has the value of “blue”E、 Bax has the value of “green”F、 The program throws an exception.

public class Test {   public static void main (String args) {  string foo = “blue”;  string bar = foo;   foo = “green”;   System.out.printIn(bar);   }   }   What is the result?()  A、 An exception is thrown.B、 The code will not compile.C、 The program prints “null”D、 The program prints “blue”E、 The program prints “green”

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、 foofoofoofoofooB、 foobarfoobarbarC、 foobarfoofoofooD、 foobarfoobarfooE、 barbarbarbarbarF、 foofoofoobarbarG、 foofoofoobarfoo

public class Test {   public static void main (String args) {   class Foo {   public int i = 3;  }   Object o = (Object) new Foo();   Foo foo = (Foo)o;   System.out.printIn(foo. i);  }   }   What is the result?()  A、 Compilation will fail.B、 Compilation will succeed and the program will print “3”C、 Compilation will succeed but the program will throw a ClassCastException at line 6.D、 Compilation will succeed but the program will throw a ClassCastException at line 7.

package foo;  import java.util.Vector; private class MyVector extends Vector {  int i = 1;  public MyVector() {  i = 2; } }  public class MyNewVector extends MyVector {  public MyNewVector() {  i = 4;  }  public static void main(String args[]) {  MyVector v = new MyNewVector();  }  }  What is the result?()A、 Compilation succeeds.B、 Compilation fails because of an error at line 5.C、 Compilation fails because of an error at line 6.D、 Compilation fails because of an error at line 14.E、 Compilation fails because of an error at line 17.

class One {   public One foo() { return this; }  }  class Two extends One {  public One foo() { return this; }  }  class Three extends Two {   // insert method here  }  Which two methods, inserted individually, correctly complete the Three class?()A、 public void foo() { }B、 public int foo() { return 3; }C、 public Two foo() { return this; }D、 public One foo() { return this; }E、 public Object foo() { return this; }

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’)(i2); foo(‘C’)){  i++ ;  foo(‘D’);  }  }  }  What is the result?()  A、 ABDCBDCBB、 ABCDABCDC、 Compilation fails.D、 An exception is thrown at runtime.

1. interface foo {  2. int k = 0;  3. } 4.    5. public class test implements Foo (  6. public static void main(String args[]) (  7. int i;  8. Test test = new test ();  9. i= test.k;  10.i= Test.k;  11.i= Foo.k;  12.)  13.)  14.        What is the result?()  A、 Compilation succeeds.B、 An error at line 2 causes compilation to fail.C、 An error at line 9 causes compilation to fail.D、 An error at line 10 causes compilation to fail.E、 An error at line 11 causes compilation to fail.

public class test(    public int aMethod()[   static int i=0;   i++;   return I;   )    public static void main (String args){   test test = new test();    test.aMethod();   int j = test.aMethod();   System.out.printIn(j);   ]  }   What is the result?()A、 Compilation will fail.B、 Compilation will succeed and the program will print “0”C、 Compilation will succeed and the program will print “1”D、 Compilation will succeed and the program will print “2”

public class Test {  public static void main(String args[]) {  class Foo {  public int i = 3; }  Object o = (Object)new Foo();   Foo foo = (Foo)o;  System.out.println(“i = “ + foo.i); }  }  What is the result?()  A、 i = 3B、 Compilation fails.C、 A ClassCastException is thrown at line 6.D、 A ClassCastException is thrown at line 7.

public class Foo {  private int val;  public foo(int v) (val = v;)  }  public static void main (String [] args)  {  Foo a = new Foo (10);  Foo b = new Foo (10);  Foo c = a;  int d = 10;  double e = 10.0;  }  Which three logical expression evaluate to true?()A、 (a ==c)B、 (d ==e)C、 (b ==d)D、 (a ==b)E、 (b ==c)F、 (d ==10.0)

public class Foo {  public static void main(String[] args) {  try {  return;  } finally {  System.out.println( “Finally” );  }  }  }  What is the result?()A、 FinallyB、 Compilation fails.C、 The code runs with no output.D、 An exception is thrown at runtime.

1.public class Test {  2.public static void main (String args[]) {  3.class Foo {  4.public int i = 3;  5.}  6.Object o = (Object) new Foo();  7.Foo foo = (Foo)o;  8.System.out.printIn(foo. i); 9. }  10.}   What is the result?()  A、 Compilation will fail.B、 Compilation will succeed and the program will print “3”C、 Compilation will succeed but the program will throw a ClassCastException at line 6.D、 Compilation will succeed but the program will throw a ClassCastException at line 7.

public class Foo {  public int a;  public Foo() { a = 3; }  public void addFive() { a += 5; }  }  and:  public class Bar extends Foo { public int a;  public Bar() { a = 8; }  public void addFive() { this.a +=5; }  }  invoked with:  Foo foo = new Bar();  foo.addFive();  System.out.println(”Value: “+ foo.a);  What is the result?() A、 Value: 3B、 Value: 8C、 Value: 13D、 Compilation fails.E、 The code runs with no output.F、 An exception is thrown at runtime.

interface foo {   int k = 0;   }    public class test implements Foo (   public static void main(String args) (    int i;   Test test = new test ();   i= test.k;   i= Test.k;   i= Foo.k;   )   )   What is the result? ()A、 Compilation succeeds.B、 An error at line 2 causes compilation to fail.C、 An error at line 9 causes compilation to fail.D、 An error at line 10 causes compilation to fail.E、 An error at line 11 causes compilation to fail.

单选题public class Test {   public static void main (String args) {   class Foo {   public int i = 3;  }   Object o = (Object) new Foo();   Foo foo = (Foo)o;   System.out.printIn(foo. i);  }   }   What is the result?()A Compilation will fail.B Compilation will succeed and the program will print “3”C Compilation will succeed but the program will throw a ClassCastException at line 6.D Compilation will succeed but the program will throw a ClassCastException at line 7.

单选题interface foo {   int k = 0;   }    public class test implements Foo (   public static void main(String args) (    int i;   Test test = new test ();   i= test.k;   i= Test.k;   i= Foo.k;   )   )   What is the result? ()A Compilation succeeds.B An error at line 2 causes compilation to fail.C An error at line 9 causes compilation to fail.D An error at line 10 causes compilation to fail.E An error at line 11 causes compilation to fail.

单选题public class Foo {  public int a;  public Foo() { a = 3; }  public void addFive() { a += 5; }  }  and:  public class Bar extends Foo { public int a;  public Bar() { a = 8; }  public void addFive() { this.a +=5; }  }  invoked with:  Foo foo = new Bar();  foo.addFive();  System.out.println(”Value: “+ foo.a);  What is the result?()A Value: 3B Value: 8C Value: 13D Compilation fails.E The code runs with no output.F An exception is thrown at runtime.

单选题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’)(i2); foo(‘C’)){  i++ ;  foo(‘D’);  }  }  }  What is the result?()A ABDCBDCBB ABCDABCDC Compilation fails.D An exception is thrown at runtime.

单选题public class Test {  public static void main(String args[]) {  class Foo {  public int i = 3; }  Object o = (Object)new Foo();   Foo foo = (Foo)o;  System.out.println(“i = “ + foo.i); }  }  What is the result?()A i = 3B Compilation fails.C A ClassCastException is thrown at line 6.D A ClassCastException is thrown at line 7.

单选题public class Foo implements Runnable (  public void run (Thread t) {   system.out.printIn(“Running.”);   }   public static void main (String args) {   new thread (new Foo()).start();   }   )   What is the result?()A An exception is thrown.B The program exists without printing anything.C An error at line 1 causes compilation to fail.D An error at line 6 causes the compilation to fail.E “Running” is printed and the program exits.

单选题public class test(  public int aMethod()[  static int i=0;  i++;  return I;  )  public static void main (String args[]){  test test = new test();  test.aMethod();  int j = test.aMethod();  System.out.printIn(j);  ]  }        What is the result?()A Compilation will fail.B Compilation will succeed and the program will print “0”C Compilation will succeed and the program will print “1”D Compilation will succeed and the program will print “2”

单选题public class Test {  public static void main (String [] args)  {  string foo = “blue”;  string bar = foo;  foo = “green”;  System.out.printIn(bar);  }  }   What is the result?()A An exception is thrown.B The code will not compile.C The program prints “null”D The program prints “blue”E The program prints “green”

单选题1.public class Test {  2.public static void main (String args[]) {  3.class Foo {  4.public int i = 3;  5.}  6.Object o = (Object) new Foo();  7.Foo foo = (Foo)o;  8.System.out.printIn(foo. i); 9. }  10.}   What is the result?()A Compilation will fail.B Compilation will succeed and the program will print “3”C Compilation will succeed but the program will throw a ClassCastException at line 6.D Compilation will succeed but the program will throw a ClassCastException at line 7.

单选题package foo;   import java.util.Vector;   private class MyVector extends Vector {  int i = 1;   public MyVector() {   i = 2;  }   }   public class MyNewVector extends MyVector {   public MyNewVector () {   i = 4;   }   public static void main (String args ) {    MyVector v = new MyNewVector();   }   }   The file MyNewVector.java is shown in the exhibit.  What is the result?()A Compilation will succeed.B Compilation will fail at line 5.C Compilation will fail at line 6.D Compilation will fail at line 14.E Compilation will fail at line 17.

单选题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 foofoofoofoofooB foobarfoobarbarC foobarfoofoofooD foobarfoobarfooE barbarbarbarbarF foofoofoobarbarG foofoofoobarfoo

单选题1. interface foo {  2. int k = 0;  3. } 4.    5. public class test implements Foo (  6. public static void main(String args[]) (  7. int i;  8. Test test = new test ();  9. i= test.k;  10.i= Test.k;  11.i= Foo.k;  12.)  13.)  14.        What is the result?()A Compilation succeeds.B An error at line 2 causes compilation to fail.C An error at line 9 causes compilation to fail.D An error at line 10 causes compilation to fail.E An error at line 11 causes compilation to fail.