restore 400
restore 403
restore 453
Compilation fails.
An exception is thrown at runtime.
第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; } }
第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: }} }}
第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?()
第4题:
What produces a compiler error?()
第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?()
第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?()
第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?()
第8题:
int addValue( int a, int b ){// do something...}
public void addValue (){// do something...}
public int addValue( int a ){// do something...}
public int addValue( int a, int b )throws MyException {//do something...}
第9题:
Compilation fails.
1 restored 42
12 restored 42
121 restored 42
1212 restored 42
An exception is thrown at runtime.
第10题:
restore 400
restore 403
restore 453
Compilation fails.
An exception is thrown at runtime.
第11题:
public int hashCode()
public boolean equals(Key k)
public int compareTo(Object o)
public boolean equals(Object o)
public boolean compareTo(Key k)
第12题:
class A { public A(int x) {} }
class A {} class B extends A { B() {} }
class A { A() {} } class B { public B() {} }
class Z { public Z(int) {} } class A extends Z {}
第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 { }
第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; } }
第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?()
第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?()
第17题:
public class Parent { int change() {…} } class Child extends Parent { } Which methods can be added into class Child?()
第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?()
第19题:
It can be any class.
No class has access to base.
The class must belong to the geometry package.
The class must be a subclass of the class Hypotenuse.
第20题:
public int change(){}
int chang(int i){}
private int change(){}
abstract int chang(){}
第21题:
s.defaultReadObject();
this = s.defaultReadObject();
y = s.readInt(); x = s.readInt();
x = s.readInt(); y = s.readInt();
第22题:
public void foo() { }
public int foo() { return 3; }
public Two foo() { return this; }
public One foo() { return this; }
public Object foo() { return this; }
第23题:
public class Circle implements Shape { private int radius; }
public abstract class Circle extends Shape { private int radius; }
public class Circle extends Shape { private int radius; public void draw(); }
public abstract class Circle implements Shape { private int radius; public void draw(); }
public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }
第24题:
Line 4 of class Target can be changed to return i++;
Line 2 of class Target can be changed to private int i = 1;
Line 3 of class Target can be changed to private int addOne() {
Line 2 of class Target can be changed to private Integer i = 0;