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.

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、 4321
  • B、 0000
  • C、 An exception is thrown at runtime.
  • D、 Compilation fails because of an error in line 18.

相关考题:

Given:10. interface Data { public void load(); }11. abstract class Info { public abstract void load(); }Which class correctly uses the Data interface and Info class?()() A.B.C.D.E.F.

下面程序输出的结果为 #include"iostream.h" class A { public: A(){cout<<"CLASSA"<<endl;} ~A() {} }; class B:public A { public: B(){cout<<"CLASSB"<<endl;} ~B() {} }; void main() { A * p; p=new B; B *q; q=new B; }A.CLASS A CLASS BB.CLASS A CLASS B CLASS BC.CLASS A CLASS B CLASS A CLASS BD.CLASS A CLASS B CLASS B CLASS B

下面程序输出的结果为#include"iostream.h"class A{public:A( ){cout<<"CLASS A"<<endl;}~A( ){}};class B:public A{public:B( ){cout<<"CLASS B"<<endl;}~B( ){}};void main( ){A*p;p=new B;B *q;q=new B;}A.CLASS A CLASS BB.CLASS A CLASS B CLASS BC.CLASS A CLASS B CLASS A CLASS BD.CLASS A CLASS B CLASS B CLASS B

下面程序输出的结果为 #include"iostream.h” class A { public: A(){cout<<"CLASSA"<<endl;} ~A() {} }; class B:public A { public: B(){cout<<"CLASS B"<<endl;} ~B(){} }; void main() { A*p; p=new B;A.CLASS A CLASS B CLASS B CLASS BB.CLASS A CLASS B CLASS A CLASS BC.CLASS A CLASS B CLASS BD.CLASS A CLASS B

下面程序输出的结果为( )。 #inClUde”iostream.h” Class A {public: A(){cout<<“CLASS A”<<endl;} ~A()<)}; class B:public A {public: B(){cout<<”CLASSB”<<endl;} ~B(){}}; void main() {A*p; p=new B; B *q; q=new B;}A.CLASS A CLASS BB.CLASS A CLASS B CLASS BC.CLASS A ClASS BD.CLASS A CLASS B CLASS A CLASS B CLASS B CLASS B

10. public class ClassA {  11. public void count(int i) {  12. count(++i);  13. }  14. }  And:  20. ClassA a = new ClassA();  21. a.count(3);  Which exception or error should be thrown by the virtual machine?() A、 StackOverflowErrorB、 NullPointerExceptionC、 NumberFormatExceptionD、 IllegalArgumentExceptionE、 ExceptionlnlnitializerError

Class TestException  1. public class TestException extends Exception {  2. } Class a:  1. public class a {  2.  3. public String sayHello(String name) throws TestException {  4.  5. if(name == null) {  6. throw new TestException();  7. }  8.  9. return “Hello “+ name;  10. }  11.  12. }  A programmer wants to use this code in an application: 45. A a=new A();  46. System.out.println(a.sayHello(”John”));  Which two are true?()A、 Class a will not compile.B、 Line 46 can throw the unchecked exception TestException.C、 Line 45 can throw the unchecked exception TestException.D、 Line 46 will compile if the enclosing method throws a TestException.E、 Line 46 will compile if enclosed in a try block, where TestException is caught.

1. public class a {  2. public void method1() {  3. try {  4. B b=new b();  5. b.method2();  6. // more code here  7. } catch (TestException te) {  8. throw new RuntimeException(te);  9. }  10. }  11. }  1. public class b {  2. public void method2() throws TestException {  3. // more code here  4. }  5. }  1. public class TestException extends Exception {  2. }  Given:  31. public void method() {  32. A a=new a();  33. a.method1();  34. }  Which is true if a TestException is thrown on line 3 of class b?()A、 Line 33 must be called within a try block.B、 The exception thrown by method1 in class a is not required to be caught.C、 The method declared on line 31 must be declared to throw a RuntimeException.D、 On line 5 of class a, the call to method2 of class b does not need to be placed in a try/catch block.

10. class Line {  11. public static class Point { }  12. }  13.  14. class Triangle {  15. // insert code here  16. }  Which code, inserted at line 15, creates an instance of the Point class defined in Line?() A、 Point p = new Point();B、 Line.Point p = new Line.Point();C、 The Point class cannot be instatiated at line 15.D、 Line 1 = new Line() ; 1.Point p = new 1.Point();

10. abstract public class Employee {  11. protected abstract double getSalesAmount();  12. public double getCommision() {  13. return getSalesAmount() * 0.15;  14. }  15. }  16. class Sales extends Employee {  17. // insert method here  18. }  Which two methods, inserted independently at line 17, correctly complete the Sales class?()A、 double getSalesAmount() { return 1230.45; }B、 public double getSalesAmount() { return 1230.45; }C、 private double getSalesAmount() { return 1230.45; }D、 protected double getSalesAmount() { return 1230.45; }

Assume that country is set for each class.  Given:  10. public class Money {  11. private String country, name;  12. public getCountry() { return country; }  13.}  and:  24. class Yen extends Money {  25. public String getCountry() { return super.country; }  26. }  27.  28. class Euro extends Money {  29. public String getCountry(String timeZone) {  30. return super.getCountry();  31. }  32. }  Which two are correct?()A、 Yen returns correct values.B、 Euro returns correct values.C、 An exception is thrown at runtime.D、 Yen and Euro both return correct values.E、 Compilation fails because of an error at line 25.F、 Compilation fails because of an error at line 30.

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.

单选题1. class A {  2. public String toString ()  {  3. return “4”;  4. }  5. }  6. class B extends A {  7. public String toString ()   {  8. return super.toString()  + “3”;  9. }  10. }  11. public class Test {  12.   public static void main(String[]args)  {  13.      System.out.printIn(new B());  14.      }  15. }    What is the result?()A Compilation succeeds and 4 is printed.B Compilation succeeds and 43 is printed.C An error on line 9 causes compilation to fail.D An error on line 14 causes compilation to fail.E Compilation succeeds but an exception is thrown at line 9.

多选题Given:   10. class One {   11. void foo() { }   12. }   13. class Two extends One {   14. //insert method here   15. }   Which three methods, inserted individually at line 14, will correctly complete class Two?()Apublic void foo() { /* more code here */ }Bprivate void foo() { /* more code here */ }Cprotected void foo() { /* more code here */ }Dint foo() { /* more code here */ }Evoid foo() { /* more code here */ }

多选题Class TestException  1. public class TestException extends Exception {  2. } Class a:  1. public class a {  2.  3. public String sayHello(String name) throws TestException {  4.  5. if(name == null) {  6. throw new TestException();  7. }  8.  9. return “Hello “+ name;  10. }  11.  12. }  A programmer wants to use this code in an application: 45. A a=new A();  46. System.out.println(a.sayHello(”John”));  Which two are true?()AClass a will not compile.BLine 46 can throw the unchecked exception TestException.CLine 45 can throw the unchecked exception TestException.DLine 46 will compile if the enclosing method throws a TestException.ELine 46 will compile if enclosed in a try block, where TestException is caught.

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

单选题A programmer is designing a class to encapsulate the information about an inventory item. A JavaBeans component is needed to do this. The Inventoryltem class has private instance variables to store the item information:  10. private int itemId;  11. private String name;  12. private String description;  Which method signature follows the JavaBeans naming standards for modifying the itemld instance variable?()A itemID(int itemId)B update(int itemId)C setItemId(int itemId)D mutateItemId(int itemId)E updateItemID(int itemId)

单选题10. class Line {  11. public static class Point { }  12. }  13.  14. class Triangle {  15. // insert code here  16. }  Which code, inserted at line 15, creates an instance of the Point class defined in Line?()A Point p = new Point();B Line.Point p = new Line.Point();C The Point class cannot be instatiated at line 15.D Line 1 = new Line() ; 1.Point p = new 1.Point();

单选题10. class Line {  11. public class Point { public int x,y; }  12. public Point getPoint() { return new Point(); }  13. }  14. class Triangle {  15. public Triangle() {  16. // insert code here  17. }  18. }  Which code, inserted at line 16, correctly retrieves a local instance of a Point object?()A Point p = Line.getPoint();B Line.Point p = Line.getPoint();C Point p = (new Line()).getPoint();D Line.Point p = (new Line()).getPoint();

单选题10. interface Foo {}  11. class Alpha implements Foo {}  12. class Beta extends Alpha {}  13. class Delta extends Beta {  14. public static void main( String[] args) {  15. Beta x = new Beta();  16. // insert code here  17. }  18. }  Which code, inserted at line 16, will cause a java.lang.ClassCastException?()A Alpha a = x;B Foo f= (Delta)x;C Foo f= (Alpha)x;D Beta b = (Beta)(Alpha)x;

单选题1. public class a {  2. public void method1() {  3. try {  4. B b=new b();  5. b.method2();  6. // more code here  7. } catch (TestException te) {  8. throw new RuntimeException(te);  9. }  10. }  11. }  1. public class b {  2. public void method2() throws TestException {  3. // more code here  4. }  5. }  1. public class TestException extends Exception {  2. }  Given:  31. public void method() {  32. A a=new a();  33. a.method1();  34. }  Which is true if a TestException is thrown on line 3 of class b?()A Line 33 must be called within a try block.B The exception thrown by method1 in class a is not required to be caught.C The method declared on line 31 must be declared to throw a RuntimeException.D On line 5 of class a, the call to method2 of class b does not need to be placed in a try/catch block.

单选题10. public class ClassA {  11. public void count(int i) {  12. count(++i);  13. }  14. }  And:  20. ClassA a = new ClassA();  21. a.count(3);  Which exception or error should be thrown by the virtual machine?()A StackOverflowErrorB NullPointerExceptionC NumberFormatExceptionD IllegalArgumentExceptionE ExceptionlnlnitializerError

单选题11. abstract class Vehicle { public int speed() { return 0; } }  12. class Car extends Vehicle { public int speed() { return 60; } }  13. class RaceCar extends Car { public int speed() { return 150; }}  ......  21. RaceCar racer = new RaceCar();  22. Car car = new RaceCar();  23. Vehicle vehicle = new RaceCar();  24. System.out.println(racer.speed() + “, „ + car.speed()  25. + “, “+ vehicle.speed());  What is the result?()A 0, 0,0B 150, 60, 0C Compilation fails.D 150, 150, 150E An exception is thrown at runtime.

多选题10. class Foo {  11. static void alpha() { /* more code here */ }  12. void beta() { /* more code here */ }  13. }  Which two are true?()AFoo.beta() is a valid invocation of beta().BFoo.alpha() is a valid invocation of alpha().CMethod beta() can directly call method alpha().DMethod alpha() can directly call method beta().

多选题1. class Super {  2. private int a;  3. protected Super(int a) { this.a = a; }  4. }  .....  11. class Sub extends Super {  12. public Sub(int a) { super(a); }  13. public Sub() { this.a= 5; }  14. }  Which two, independently, will allow Sub to compile?()AChange line 2 to: public int a;BChange line 2 to: protected int a;CChange line 13 to: public Sub() { this(5); }DChange line 13 to: public Sub() { super(5); }EChange line 13 to: public Sub() { super(a); }

单选题10. public class ClassA {  11. public void methodA() {  12. ClassB classB = new ClassB();  13. classB.getValue();  14. }  15. }  And:  20. class ClassB {  21. public ClassC classC;  22.  23. public String getValue() {  24. return classC.getValue();  25. }  26. }  And:  30. class ClassC {  31. public String value;  32.  33. public String getValue() {  34. value = “ClassB”;  35. return value;  36. }  37. }  Given:  ClassA a = new ClassA();  a.methodA();  What is the result?()A Compilation fails.B ClassC is displayed.C The code runs with no output.D An exception is thrown at runtime.

单选题1. class Alpha { void m1() {} }   2. class Beta extends Alpha { void m2() { } }   3. class Gamma extends Beta { }   4.   5. class GreekTest {   6. public static void main(String [] args) {   7. a Alpha [] a = {new Alpha(), new Beta(), new Gamma() };   8. for(Alpha a2 : a) {   9. a2.m1();   10. if (a2 instanceof Beta || a2 instanceof Gamma)   11. //insert code here   12. }   13. }   14. }   哪一行代码插入到第11行,将编译但是会在运行时产生异常?()A a2.m2();B ((Beta)a2).m2();C ((Alpha)a2).m2();D ((Gamma)a2).m2();

单选题10. class Nav{  11. public enum Direction { NORTH, SOUTH, EAST, WEST }  12. }  13. public class Sprite{  14. // insert code here  15. }  Which code, inserted at line 14, allows the Sprite class to compile?()A Direction d = NORTH;B Nav.Direction d = NORTH;C Direction d = Direction.NORTH;D Nav.Direction d = Nav.Direction.NORTH;