11. public static void main(String[] args) {  12. Object obj = new Object() {  13. public int hashCode() {  14. returns 42; 15. }  16. };  17. System.out.println(obj.hashCode());  18. }    What is the result? () A、 42B、 An exception is thrown at runtime.C、 Compilation fails because of an error on line 12.D、 Compilation fails because of an error on line 16.E、 Compilation fails because of an error on line 17.

11. public static void main(String[] args) {  12. Object obj = new Object() {  13. public int hashCode() {  14. returns 42; 15. }  16. };  17. System.out.println(obj.hashCode());  18. }    What is the result? () 

  • A、 42
  • B、 An exception is thrown at runtime.
  • C、 Compilation fails because of an error on line 12.
  • D、 Compilation fails because of an error on line 16.
  • E、 Compilation fails because of an error on line 17.

相关考题:

11. public static void main(String[] args) {  12. Object obj =new int[] { 1,2,3 };  13. int[] someArray = (int[])obj;  14. for (int i: someArray) System.out.print(i +“ “)  15. }  What is the result? ()A、 1 2 3B、 Compilation fails because of an error in line 12.C、 Compilation fails because of an error in line 13.D、 Compilation fails because of an error in line 14.E、 A ClassCastException is thrown at runtime.

public class ItemTest {  private final mt id;  public ItemTest(int id) { this.id = id; }  public void updateId(int newId) { id = newId; }  public static void main(String[] args) {  ItemTest fa = new ItemTest(42);  fa.updateId(69);  System.out.println(fa.id);  }  }  What is the result?() A、 Compilation fails.B、 An exception is thrown at runtime.C、 The attribute id in the Item object remains unchanged.D、 The attribute id in the Item object is modified to the new value.E、 A new Item object is created with the preferred value in the id attribute.

11. public enum Title {  12. MR(”Mr.”), MRS(”Mrs.”), MS(”Ms.”);  13. private final String title;  14. private Title(String t) { title = t; }  15. public String format(String last, String first) {  16. return title + “ “ + first + “ “ + last;  17. }  18. }  19. public static void main(String[] args) {  20. System.out.println(Title.MR.format(”Doe”, “John”));  21. }  What is the result?() A、 Mr. John DoeB、 An exception is thrown at runtime.C、 Compilation fails because of an error in line 12.D、 Compilation fails because of an error in line 15.E、 Compilation fails because of an error in line 20.

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.

11. public static void main(String[] args) {  12. Integer i = uew Integer(1) + new Integer(2);  13. switch(i) {  14. case 3: System.out.println(”three”); break;  15. default: System.out.println(”other”); break;  16. }  17. }  What is the result?() A、 threeB、 otherC、 An exception is thrown at runtime.D、 Compilation fails because of an error on line 12.E、 Compilation fails because of an error on line 13.F、 Compilation fails because of an error on line 15.

11. public void testIfA() {  12. if(testIfB(”True”)) {  13. System.out.println(”True”);  14. } else {  15. System.out.println(”Not true”);  16. }  17. }  18. public Boolean testIfB(String str) {  19. return Boolean.valueOf(str);  20. }  What is the result when method testIfA is invoked?() A、 TrueB、 Not trueC、 An exception is thrown at runtime.D、 Compilation fails because of an error at line 12.E、 Compilation fails because of an error at line 19.

11. static class A {  12. void process() throws Exception { throw new Exception(); }  13. }  14. static class B extends A {  15. void process() { System.out.println(”B”); }  16. }  17. public static void main(String[] args) {  18. new B().process();  19. }  What is the result?() A、 BB、 The code runs with no output.C、 Compilation fails because of an error in line 12.D、 Compilation fails because of an error in line 15.E、 Compilation fails because of an error in line 18.

11. class Converter {  12. public static void main(String[] args) {  13. Integer i = args[0];  14. int j = 12;  15. System.out.println(”It is “ + (j==i) + “that j==i.”);  16. }  17. }  What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?() A、 It is true that j==i.B、 It is false that j==i.C、 An exception is thrown at runtime.D、 Compilation fails because of an error in line 13.

1. public class Test { 2. public static String output =””; 3.  4. public static void foo(int i) { 5. try { 6. if(i==1) { 7. throw new Exception(); 8. } 9. output += “1”; 10. } 11. catch(Exception e) { 12. output += “2”; 13. return; 14. } 15. finally { 16. output += “3”;17. } 18. output += “4”; 19. } 20.  21. public static void main(String args[]) { 22. foo(0); 23. foo(1); 24.  25. }26. } What is the value of the variable output at line 23?()

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.

11.classA {  12. public void process() { System.out.print(”A “); } }  13. class B extends A {  14. public void process() throws RuntimeException {  15. super.process();  16. if (true) throw new RuntimeException();  17. System.out.print(“B”); }}  18. public static void main(String[] args) {  19. try { ((A)new B()).process(); }  20. catch (Exception e) { System.out.print(”Exception “); }  21. }  What is the result?() A、 ExceptionB、 A ExceptionC、 A Exception BD、 A B ExceptionE、 Compilation fails because of an error in line 14.F、 Compilation fails because of an error in line 19.

11. class Person {  12. String name = “No name‟;  13. public Person(String nm) { name = nm; }  14. }  15.  16. class Employee extends Person {  17. String emplD = “0000”;  18. public Employee(String id) { empID = id; }  19. }  20.  21. public class EmployeeTest {  22. public static void main(String[] args) {  23. Employee e = new Employee(”4321”);  24. System.out.println(e.empID);  25. }  26. }  What is the result?() A、 4321B、 0000C、 An exception is thrown at runtime.D、 Compilation fails because of an error in line 18.

10. public class Hello {  11. String title;  12. int value;  13. public Hello() {  14. title += “ World”;  15. }  16. public Hello(int value) {  17. this.value = value;  18. title = “Hello”;  19. Hello();  20. }  21. }  and:  30. Hello c = new Hello(5);  31. System.out.println(c.title);  What is the result?() A、 HelloB、 Hello WorldC、 Compilation fails.D、 Hello World 5E、 The code runs with no output.F、 An exception is thrown at runtime.

11. public static void append(List list) { list.add(”0042”); }  12. public static void main(String[] args) {  13. List intList = new ArrayList();  14. append(intList);  15. System.out.println(intList.get(0));  16. }  What is the result?() A、 42B、 0042C、 An exception is thrown at runtime.D、 Compilation fails because of an error in line 13.E、 Compilation fails because of an error in line 14.

11.classa {  12. public void process() { System.out.print(”a,”); } }  13. class b extends a {  14. public void process() throws IOException {  15. super.process();  16. System.out.print(”b,”);  17. throw new IOException();  18. } }  19. public static void main(String[] args) {  20. try { new b().process(); }  21. catch (IOException e) { System.out.println(”Exception”); } }  What is the result?() A、 ExceptionB、 a,b,ExceptionC、 Compilation fails because of an error in line 20.D、 Compilation fails because of an error in line 14.E、 A NullPointerException is thrown at runtime.

11. static classA {  12. void process() throws Exception { throw new Exception(); }  13. }  14. static class B extends A {  15. void process() { System.out.println(”B “); }  16. }  17. public static void main(String[] args) {  18.A a=new B();  19. a.process();  20.}  What is the result?() A、 BB、 The code runs with no output.C、 An exception is thrown at runtime.D、 Compilation fails because of an error in line 15.E、 Compilation fails because of an error in line 18.F、 Compilation fails because of an error in line 19.

11. public static void test(String str) {  12. if(str == null | str.lellgth() == 0) {  13. System.out.println(”String is empty”);  14. } else {  15. System.out.println(”String is not empty”);  16. }  17. }  And the invocation:  31. test(llull);  What is the result?() A、 Au exception is thrown at runtime.B、 “String is empty” is printed to output.C、 Compilation fails because of au error in line 12.D、 “String is not empty” is printed to output.

Given:   11. static class A {   12. void process() throws Exception { throw new Exception(); }   13. }   14. static class B extends A {   15. void process() { System.out.println("B "); }   16. }   17. public static void main(String[] args) {   18. A a = new B();   19. a.process();   20. }   What is the result? ()A、 Compilation fails because of an error in line 19.B、 An exception is thrown at runtime.C、 BD、 Compilation fails because of an error in line 18.E、 Compilation fails because of an error in line 15. F、 The code runs with no output.

单选题11. static classA {  12. void process() throws Exception { throw new Exception(); }  13. }  14. static class B extends A {  15. void process() { System.out.println(”B “); }  16. }  17. public static void main(String[] args) {  18.A a=new B();  19. a.process();  20.}  What is the result?()A BB The code runs with no output.C An exception is thrown at runtime.D Compilation fails because of an error in line 15.E Compilation fails because of an error in line 18.F Compilation fails because of an error in line 19.

单选题11. public static void append(List list) { list.add(”0042”); }  12. public static void main(String[] args) {  13. List intList = new ArrayList();  14. append(intList);  15. System.out.println(intList.get(0));  16. }  What is the result?()A 42B 0042C An exception is thrown at runtime.D Compilation fails because of an error in line 13.E Compilation fails because of an error in line 14.

单选题11. public static void main(String[] args) {  12. Object obj =new int[] { 1,2,3 };  13. int[] someArray = (int[])obj;  14. for (int i: someArray) System.out.print(i +“ “)  15. }  What is the result? ()A 1 2 3B Compilation fails because of an error in line 12.C Compilation fails because of an error in line 13.D Compilation fails because of an error in line 14.E A ClassCastException is thrown at runtime.

单选题11. public static void main(String[] args) {  12. Object obj = new Object() {  13. public int hashCode() {  14. returns 42; 15. }  16. };  17. System.out.println(obj.hashCode());  18. }    What is the result? ()A 42B An exception is thrown at runtime.C Compilation fails because of an error on line 12.D Compilation fails because of an error on line 16.E Compilation fails because of an error on line 17.

单选题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.

单选题11. public static void main(String[] args) {  12. Integer i = uew Integer(1) + new Integer(2);  13. switch(i) {  14. case 3: System.out.println(”three”); break;  15. default: System.out.println(”other”); break;  16. }  17. }  What is the result?()A threeB otherC An exception is thrown at runtime.D Compilation fails because of an error on line 12.E Compilation fails because of an error on line 13.F Compilation fails because of an error on line 15.

单选题Given:   11. static class A {   12. void process() throws Exception { throw new Exception(); }   13. }   14. static class B extends A {   15. void process() { System.out.println("B "); }   16. }   17. public static void main(String[] args) {   18. A a = new B();   19. a.process();   20. }   What is the result? ()A Compilation fails because of an error in line 19.B An exception is thrown at runtime.C BD Compilation fails because of an error in line 18.E Compilation fails because of an error in line 15. F The code runs with no output.

单选题Given:   11. public static void main(String[] args) {   12. Object obj = new int[] { 1, 2, 3 };   13. int[] someArray = (int[])obj;   14. for (int i : someArray) System.out.print(i + " ");   15. }   What is the result? ()A Compilation fails because of an error in line 13.B A ClassCastException is thrown at runtime.C 1 2 3D Compilation fails because of an error in line 14.E Compilation fails because of an error in line 12.

单选题11. static class A {  12. void process() throws Exception { throw new Exception(); }  13. }  14. static class B extends A {  15. void process() { System.out.println(”B”); }  16. }  17. public static void main(String[] args) {  18. new B().process();  19. }  What is the result?()A BB The code runs with no output.C Compilation fails because of an error in line 12.D Compilation fails because of an error in line 15.E Compilation fails because of an error in line 18.