单选题Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:  import java.io.*;  class Food implemertts Serializable {int good = 3;}  class Fruit externds Food {int juice = 5;}  public class B

题目
单选题
Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:  import java.io.*;  class Food implemertts Serializable {int good = 3;}  class Fruit externds Food {int juice = 5;}  public class Banana extends Fruit {  int yellow = 4;  public static void main(String [] args) {  Banana b = new Banana(); Banana b2 = new Banana();  b.serializeBanana(b); // assume correct serialization  b2 = b.deserializeBanana(); // assume correct  System.out.println(”restore “+b2.yellow+ b2.juice+b2.good);  }  // more Banana methods go here  }  What is the result?()
A

 restore 400

B

 restore 403

C

 restore 453

D

 Compilation fails.

E

 An exception is thrown at runtime.


相似考题
更多“单选题Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:  import java.io.*;  class Food implemertts Serializable {int good = 3;}  class Fruit externds Food {int juice = 5;}  public class B”相关问题
  • 第1题:

    在下列源代码文件Test.java中,正确定义类的代码是( )。

    A.pblic class test { public int x=0; public test(int x) { this. x=x;} }

    B.public class Test { public int x=0; public Test(int x) { this. x=x;} }

    C.public class Test extends T1,T2{ public int x = 0; public Test(int x){ this. x = x; } }

    D.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }


    正确答案:B
    解析:本题主要考查类声明格式为[修饰符]class类名[extends父类名][implements类实现的接口列表],选项A中源文件名与程序名不相同,Java不支持多重继承所以选项C错误,选项D中类的访问权限不对,应为public。

  • 第2题:

    在下列源代码文件Test.java中, ( )是正确的类定义。

    A.public class test{

    B.public class Test{ public int x=0;public int x=0; public test (intx) public Test (int x){ {this.x=x; this.x=x;} }} }

    C.public class Test extends T1,T2{

    D.protected class Test extends T2{ public int=0;public int x=0; public Test(int x){Public Test (int x){ this.x=x;this.x=x: }} }}


    正确答案:B

  • 第3题:

    Assuming that the serializeBanana2() and the deserializeBanana2() methods will correctly use Java serialization and given:  import java.io.*;  class Food {Food() { System.out.print(”1”); } }  class Fruit extends Food implements Serializable {  Fruit() { System.out.print(”2”); } }  public class Banana2 extends Fruit { int size = 42;  public static void main(String [] args) {  Banana2 b = new Banana2();  b.serializeBanana2(b); // assume correct serialization  b = b.deserializeBanana2(b); // assume correct  System.out.println(” restored “+ b.size + “ “); }  // more Banana2 methods  }  What is the result?() 

    • A、 Compilation fails.
    • B、 1 restored 42
    • C、 12 restored 42
    • D、 121 restored 42
    • E、 1212 restored 42
    • F、 An exception is thrown at runtime.

    正确答案:D

  • 第4题:

    What produces a compiler error?()  

    • A、 class A { public A(int x) {} }
    • B、 class A {} class B extends A { B() {} }
    • C、 class A { A() {} } class B { public B() {} }
    • D、 class Z { public Z(int) {} } class A extends Z {}

    正确答案:D

  • 第5题:

    Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:  import java.io.*;  class Food implemertts Serializable {int good = 3;}  class Fruit externds Food {int juice = 5;}  public class Banana extends Fruit {  int yellow = 4;  public static void main(String [] args) {  Banana b = new Banana(); Banana b2 = new Banana();  b.serializeBanana(b); // assume correct serialization  b2 = b.deserializeBanana(); // assume correct  System.out.println(”restore “+b2.yellow+ b2.juice+b2.good);  }  // more Banana methods go here  }  What is the result?() 

    • A、 restore 400
    • B、 restore 403
    • C、 restore 453
    • D、 Compilation fails.
    • E、 An exception is thrown at runtime.

    正确答案:C

  • 第6题:

    1. import java.io.*;  2. public class Foo implements Serializable {  3. public int x, y;  4. public Foo( int x, int y) { this.x = x; this.y = y; }  5.  6. private void writeObject( ObjectOutputStream s)  7. throws IOException {  8. s.writeInt(x); s.writeInt(y)  9. }  10.  11. private void readObject( ObjectInputStream s)  12. throws IOException, ClassNotFoundException {  13.  14. // insert code here  15.  16. }  17. }  Which code, inserted at line 14, will allow this class to correctly serialize and deserialize?() 

    • A、 s.defaultReadObject();
    • B、 this = s.defaultReadObject();
    • C、 y = s.readInt(); x = s.readInt();
    • D、 x = s.readInt(); y = s.readInt();

    正确答案:D

  • 第7题:

    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()

    • A、 public class Circle implements Shape { private int radius; }
    • B、 public abstract class Circle extends Shape { private int radius; }
    • C、 public class Circle extends Shape { private int radius; public void draw(); }
    • D、 public abstract class Circle implements Shape { private int radius; public void draw(); }
    • E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
    • F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

    正确答案:B,E

  • 第8题:

    多选题
    public class Parent {  public int addValue( int a, int b) {     int s;     s = a+b;     return s;     }     }  class Child extends Parent {  }  Which methods can be added into class Child?()
    A

    int addValue( int a, int b ){// do something...}

    B

    public void addValue (){// do something...}

    C

    public int addValue( int a ){// do something...}

    D

    public int addValue( int a, int b )throws MyException {//do something...}


    正确答案: B,D
    解析: 此题涉及方法重载(overload),方法重写(override)以及类派生时方法重写的规则。方法重载的规则是:
    一、参数列表必须不同,个数的不同完全可以,如果个数相同则参数类型的不同不能引起歧意,例如int 和long,float和double就不能作为唯一的类型不同;
    二、返回值可以不同,但是不能是重载时唯一的不同点(这点和c++中不同,c++中返回类型必须一致)。
    方法重写发生在类继承时,子类可以重写一个父类中已有的方法,必须在返回类型和参数列表一样时才能说是重写,否则就是重载,java中方法重写的一个重要而且容易被忽略的规则是重写的方法的访问权限不能比被重写的方法的访问权限低!重写的另一个规则是重写的方法不能比被重写的方法抛弃(throws)更多种类的异常,其抛弃的异常只能少,或者是其子类,不能以抛弃异常的个数来判断种类,而应该是异常类层次结果上的种类。此题中答案a的错误就是重写的访问权限比被重写的方法的低,而b,c都属于重载,d的错误在于比被重写的方法抛弃了更多种类的异常。

  • 第9题:

    单选题
    Assuming that the serializeBanana2() and the deserializeBanana2() methods will correctly use Java serialization and given:  import java.io.*;  class Food {Food() { System.out.print(”1”); } }  class Fruit extends Food implements Serializable {  Fruit() { System.out.print(”2”); } }  public class Banana2 extends Fruit { int size = 42;  public static void main(String [] args) {  Banana2 b = new Banana2();  b.serializeBanana2(b); // assume correct serialization  b = b.deserializeBanana2(b); // assume correct  System.out.println(” restored “+ b.size + “ “); }  // more Banana2 methods  }  What is the result?()
    A

     Compilation fails.

    B

     1 restored 42

    C

     12 restored 42

    D

     121 restored 42

    E

     1212 restored 42

    F

     An exception is thrown at runtime.


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

  • 第10题:

    单选题
    Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:  import java.io.*;  class Food implemertts Serializable {int good = 3;}  class Fruit externds Food {int juice = 5;}  public class Banana extends Fruit {  int yellow = 4;  public static void main(String [] args) {  Banana b = new Banana(); Banana b2 = new Banana();  b.serializeBanana(b); // assume correct serialization  b2 = b.deserializeBanana(); // assume correct  System.out.println(”restore “+b2.yellow+ b2.juice+b2.good);  }  // more Banana methods go here  }  What is the result?()
    A

     restore 400

    B

     restore 403

    C

     restore 453

    D

     Compilation fails.

    E

     An exception is thrown at runtime.


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

  • 第11题:

    多选题
    public class Key {  private long id1;  private long 1d2;  // class Key methods  }  A programmer is developing a class Key, that will be used as a key in a standard java.util.HashMap. Which two methods should be overridden to assure that Key works correctly as a key?()
    A

    public int hashCode()

    B

    public boolean equals(Key k)

    C

    public int compareTo(Object o)

    D

    public boolean equals(Object o)

    E

    public boolean compareTo(Key k)


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

  • 第12题:

    单选题
    What produces a compiler error?()
    A

     class A { public A(int x) {} }

    B

     class A {} class B extends A { B() {} }

    C

     class A { A() {} } class B { public B() {} }

    D

     class Z { public Z(int) {} } class A extends Z {}


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

  • 第13题:

    下列哪个选项的java源文件程序段是不正确的? ( )

    A.package testpackage; public class Test{ }

    B.import java.io.*; package testpackage; public class Test{ }

    C.import java.i.*; class Person{} public class Test{ }

    D.import java.io.*; import java.awt.*; public class Test { }


    正确答案:B

  • 第14题:

    在下列源代码文件Test.java中,哪个选项是正确的类定义?

    A.public class test{ public int x=0; public test(int x ) { this.x=x; } }

    B.public class Test { public int x=0; public Test(int x ) { this.x=x; } }

    C.public class Test extends T1 T2 { public int x=0; public Test(int x){ this.x=x; } }

    D.protected class Test extends T2 { public int x=0; public Test(int x) { this.x=x; } }


    正确答案:B
    解析:类声明格式为[修饰符]class类名[extends父类名][implements类实现的接口列表],选项A)中源文件名与程序名不相同,Java不支持多重继承所以选项C)错误,选项D)中类的访问权限不对应为public。

  • 第15题:

    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; }

    正确答案:C,D

  • 第16题:

    public class Parent {  public int addValue( int a, int b) {     int s;     s = a+b;     return s;     }     }  class Child extends Parent {  }  Which methods can be added into class Child?()   

    • A、 int addValue( int a, int b ){// do something...}
    • B、 public void addValue (){// do something...}
    • C、 public int addValue( int a ){// do something...}
    • D、 public int addValue( int a, int b )throws MyException {//do something...}

    正确答案:B,C

  • 第17题:

    public class Parent {     int change() {…}     }  class Child extends Parent {     }  Which methods can be added into class Child?()    

    • A、 public int change(){}
    • B、 int chang(int i){}
    • C、 private int change(){}
    • D、 abstract int chang(){}

    正确答案:A,B

  • 第18题:

    public class Key {  private long id1;  private long 1d2;  // class Key methods  }  A programmer is developing a class Key, that will be used as a key in a standard java.util.HashMap. Which two methods should be overridden to assure that Key works correctly as a key?()

    • A、 public int hashCode()
    • B、 public boolean equals(Key k)
    • C、 public int compareTo(Object o)
    • D、 public boolean equals(Object o)
    • E、 public boolean compareTo(Key k)

    正确答案:A,D

  • 第19题:

    单选题
    package geometry;  public class Hypotenuse {  public InnerTriangle it = new InnerTriangle();  class InnerTriangle {  public int base;  public int height;  }  }  Which is true about the class of an object that can reference the variable base? ()
    A

     It can be any class.

    B

     No class has access to base.

    C

     The class must belong to the geometry package.

    D

     The class must be a subclass of the class Hypotenuse.


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

  • 第20题:

    多选题
    public class Parent {     int change() {…}     }  class Child extends Parent {     }  Which methods can be added into class Child?()
    A

    public int change(){}

    B

    int chang(int i){}

    C

    private int change(){}

    D

    abstract int chang(){}


    正确答案: D,A
    解析: 这个题目的问题在第35题中有详尽的叙述。需要注意的是答案D的内容,子类可以重写父类的方法并将之声明为抽象方法,但是这引发的问题是类必须声明为抽象类,否则编译不能通过,而且抽象方法不能有方法体,也就是方法声明后面不能带上那两个大括号({}),这些D都不能满足。

  • 第21题:

    单选题
    1. import java.io.*;  2. public class Foo implements Serializable {  3. public int x, y;  4. public Foo( int x, int y) { this.x = x; this.y = y; }  5.  6. private void writeObject( ObjectOutputStream s)  7. throws IOException {  8. s.writeInt(x); s.writeInt(y)  9. }  10.  11. private void readObject( ObjectInputStream s)  12. throws IOException, ClassNotFoundException {  13.  14. // insert code here  15.  16. }  17. }  Which code, inserted at line 14, will allow this class to correctly serialize and deserialize?()
    A

     s.defaultReadObject();

    B

     this = s.defaultReadObject();

    C

     y = s.readInt(); x = s.readInt();

    D

     x = s.readInt(); y = s.readInt();


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

  • 第22题:

    多选题
    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; }


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

  • 第23题:

    多选题
    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()
    A

    public class Circle implements Shape { private int radius; }

    B

    public abstract class Circle extends Shape { private int radius; }

    C

    public class Circle extends Shape { private int radius; public void draw(); }

    D

    public abstract class Circle implements Shape { private int radius; public void draw(); }

    E

    public class Circle extends Shape { private int radius;public void draw() {/* code here */} }

    F

    public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }


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

  • 第24题:

    单选题
    1. public class Target {  2. private int i = 0;  3. public int addOne() {  4. return ++i;  5. }  6. }  And:  1. public class Client {  2. public static void main(String[] args) {  3. System.out.println(new Target().addOne());  4. }  5. }  Which change can you make to Target without affecting Client?()
    A

     Line 4 of class Target can be changed to return i++;

    B

     Line 2 of class Target can be changed to private int i = 1;

    C

     Line 3 of class Target can be changed to private int addOne() {

    D

     Line 2 of class Target can be changed to private Integer i = 0;


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