单选题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();

单选题
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();


参考解析

解析: 暂无解析

相关考题:

下列关于Test类的定义中,正确的是______。A) class Test implements Runnabte{public void run(){}public void someMethod(){}B) class Test implements Rnuuable{public void run();}C) class Test implements Rnuuable{public void someMethod();}D) class Test implements Rnuuable{public void someMethod();{}}A.B.C.D.

下列哪个方法可用于创建一个可运行的类? ( )A.public class X implements Runable {public void run(){...,.,}}B.public class X implements Thread {public void run(){......}}C.public class X implements Thread {public int run(){……}}D.public class X implements Runable {protected void run(){.....}}

下列哪个选项的java源文件代码片段是不正确的?A.package testpackage; public class Test{ }B.import java. io. *; package testpaekage; public class Test { }C.import java.io.*; class Person { } public class Test { }D.import java.io.*; import java. awt.*; public class Test{ }

下列程序将类C15的对象写入文件filetxt,选择正确的语句填入下列程序的横线处。 package ch2; import java.util.*; import java.io.*; class C15______ { public iht a; public void setInt(int newa) { a = newa; } } public class Testl5 { pulibc static void main(String[] args) { C15 bj = new C15(); try { FileOutputStream fos =newFileOutputStream("ch2\\filel5.txt"); ObjectOutputStream os = ObjectOutputStream(fos); Obj.setInt(10); oos.writeObject(obj); oos.close (); fos.close(); } catch(IOException ioe) { ioe.printStackTrace(); } } }A.implements RunnableB.implements SedalizableC.extends SerializableD.implements InputStream

下列代码的输出结果是( )。class parent{void printme(){System.out.println("parent");}}class child extends parent{void printme(){System. out.println("child");}void printall(){super, printme();this.printme();printme();}}public class test{public static void main(String args[]){child myc=new child();myc.printall();}}A.import java.awt.*;B.import java.applet.applet;C.import java.io.*;D.import java, awt.graphics;

下列哪个选项的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 { }

1. public interface A {  2. public void doSomething(String thing);  3. }  1. public class AImpl implements A {  2. public void doSomething(String msg) { }  3. }  1. public class B {  2. public A doit() {  3. // more code here  4. }  5.  6. public String execute() { 7. // more code here  8. }  9. }  1. public class C extends B {  2. public AImpl doit() {  3. // more code here  4. }  5.  6. public Object execute() {  7. // more code here  8. }  9. }  Which statement is true about the classes and interfaces in the exhibit?() A、 Compilation will succeed for all classes and interfaces.B、 Compilation of class C will fail because of an error in line 2.C、 Compilation of class C will fail because of an error in line 6.D、 Compilation of class AImpl will fail because of an error in line 2.

interface Data { public void load(); }  abstract class Info { public abstract void load(); }  Which class correctly uses the Data interface and Info class?() A、 public class Employee extends Info implements Data { public void load() { /*do something*/ } }B、 public class Employee implements Info extends Data { public void load() { /*do something*/ } }C、 public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }D、 public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }E、 public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }F、 public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }

下列代码正确的是哪项?() A、 public class Session implements Runnable, Clonable{   public void run ();public Object clone () ; }B、 public class Session extends Runnable, Cloneable {  public void run() {/*dosomething*/}       public Object clone() {/*make a copy*/} }C、 public abstract class Session implements Runnable, Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}        }D、 public class Session implements Runnable, implements Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}       }

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

//point X  public class foo { public static void main (String[]args) throws Exception {  java.io.printWriter out = new java.io.PrintWriter {  new java.io.outputStreamWriter (System.out), true;  out.printIn(“Hello”); }  }  }   Which statement at PointX on line 1 allows this code to compile and run?()  A、 Import java.io.*;B、 Include java.io.*;C、 Import java.io.PrintWriter;D、 Include java.io.PrintWriter;E、 No statement is needed.

2. public class Foo implements Runnable (  3. public void run (Thread t) {  4. system.out.printIn(“Running.”);  5. }  6. public static void main (String[] args)  {  7. new thread (new Foo()).start(); 8. )  9. )   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.

// Point X  public class foo {  public static void main(String[] args) throws Exception {  jave.io.PrintWriter out = new jave.io.PrintWriter(  new jave.io.OutputStreamWriter(System.out), true); out.println(“Hello”); }  }   Which statement at Point X on line 1 is required to allow this code to compile?()  A、 No statement is required.B、 import jave.io.*;C、 include java.io.*;D、 import jave.io.PrintWriter;E、 include java.io.PrintWriter;

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.

import java.io.*;  public class Forest implements Serializable {  private Tree tree = new Tree();  public static void main(String [] args) {  Forest f= new Forest();  try {  FileOutputStream fs = new FileOutputStream(”Forest.ser”);  ObjectOutputStream os = new ObjectOutputStream(fs);  os.writeObject(f); os.close();  } catch (Exception ex) { ex.printStackTrace(); }  }  }  class Tree { }  What is the result?() A、 Compilation fails.B、 An exception is thrown at runtime.C、 An instance of Forest is serialized.D、 A instance of Forest and an instance of Tree are both serialized.

多选题10. interface Foo {  11. int bar();  12. }  13.  14. public class Beta {  15.  16. class A implements Foo {  17. public int bar() { return 1; }  18. }  19.  20. public int fubar( Foo foo) { return foo.bar(); }  21.  22. public void testFoo() {  23.  24. class A implements Foo {  25. public int bar() { return 2; }  26. }  27.  28. System.out.println( fubar( new A())); 29. }  30.  31. public static void main( String[] argv) {  32. new Beta().testFoo();  33. }  34. }  Which three statements are true?()ACompilation fails.BThe code compiles and the output is 2.CIf lines 16, 17 and 18 were removed, compilation would fail.DIf lines 24, 25 and 26 were removed, compilation would fail.EIf lines 16, 17 and 18 were removed, the code would compile and the output would be 2.FIf lines 24, 25 and 26 were removed, the code would compile and the output would be 1.

单选题// Point X  public class foo {  public static void main(String[] args) throws Exception {  jave.io.PrintWriter out = new jave.io.PrintWriter(  new jave.io.OutputStreamWriter(System.out), true); out.println(“Hello”); }  }   Which statement at Point X on line 1 is required to allow this code to compile?()A No statement is required.B import jave.io.*;C include java.io.*;D import jave.io.PrintWriter;E include java.io.PrintWriter;

单选题下列代码正确的是哪项?()A public class Session implements Runnable, Clonable{   public void run ();public Object clone () ; }B public class Session extends Runnable, Cloneable {  public void run() {/*dosomething*/}       public Object clone() {/*make a copy*/} }C public abstract class Session implements Runnable, Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}        }D public class Session implements Runnable, implements Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}       }

单选题10. interface Foo { int bar(); }  11. public class Sprite {  12. public int fubar( Foo foo) { return foo.bar(); }  13. public void testFoo() {  14. fubar(  15. // insert code here  16.);  17. }  18. }  Which code, inserted at line 15, allows the class Sprite to compile?()A Foo { public int bar() { return 1; } }B new Foo { public int bar() { return 1; } }C newFoo() { public int bar(){return 1; } }D new class Foo { public int bar() { return 1; } }

单选题interface Data { public void load(); }  abstract class Info { public abstract void load(); }  Which class correctly uses the Data interface and Info class?()A public class Employee extends Info implements Data { public void load() { /*do something*/ } }B public class Employee implements Info extends Data { public void load() { /*do something*/ } }C public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }D public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }E public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }F public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }

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

单选题import java.io.*;  public class Forest implements Serializable {  private Tree tree = new Tree();  public static void main(String [] args) {  Forest f= new Forest();  try {  FileOutputStream fs = new FileOutputStream(”Forest.ser”);  ObjectOutputStream os = new ObjectOutputStream(fs);  os.writeObject(f); os.close();  } catch (Exception ex) { ex.printStackTrace(); }  }  }  class Tree { }  What is the result?()A Compilation fails.B An exception is thrown at runtime.C An instance of Forest is serialized.D A instance of Forest and an instance of Tree are both serialized.

单选题现有:  1. interface Animal {  2. void eat();  3. }  4.  5. // insert code here  6.  7. public class HouseCat extends Feline {  8. public void eat() { }  9. }   和五个声明:  abstract class Feline implements Animal { }  abstract class Feline implements Animal { void eat(); }  abstract class Feline implements Animal { public void eat(); }  abstract class Feline implements Animal { public void eat() { } }  abstract class Feline implements Animal { abstract public void eat(); }  分别插入到第5行,有几个可以通过编译?()A0B1C2D3

单选题//point X  public class foo { public static void main (String[]args) throws Exception {  java.io.printWriter out = new java.io.PrintWriter {  new java.io.outputStreamWriter (System.out), true;  out.printIn(“Hello”); }  }  }   Which statement at PointX on line 1 allows this code to compile and run?()A Import java.io.*;B Include java.io.*;C Import java.io.PrintWriter;D Include java.io.PrintWriter;E No statement is needed.

单选题现有:  interface Animal {       void eat () ;       }       //insert code here       public class HouseCat extends Feline {       public void eat() { }       }  和五个申明  abstract class Feline implements Animal { }  abstract  class  Feline  implements  Animal  {  void eat () ;  }  abstract class Feline implements Animal { public void eat();}  abstract class Feline implements Animal { public void eat() {}  }  abstract class Feline implements Animal { abstract public void eat();} 结果为:()A1B2C3D4

单选题Given a class Repetition:  1. package utils;  2.  3. public class Repetition {  4. public static String twice(String s) { return s + s; }  5. }  and given another class Demo:  1. // insert code here 2.  3. public class Demo {  4. public static void main(String[] args) {  5. System.out.println(twice(”pizza”));  6. }  7. }  Which code should be inserted at line 1 of Demo.java to compile and run Demo to print“pizzapizza”?()A import utils.*;B static import utils.*;C import utils.Repetition.*;D static import utils.Repetition. *;E import utils.Repetition.twice();F import static utils.Repetition.twice;G static import utils.Repetition.twice;

多选题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?()Apublic void foo() { }Bpublic int foo() { return 3; }Cpublic Two foo() { return this; }Dpublic One foo() { return this; }Epublic Object foo() { return this; }