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.
相关问题推荐
-
A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants to execute the main method of Poker on a UNIX system using the command: java games.cards.Poker What allows the user to do this?()
A、put Poker.jar in directory /stuff/java,and set the CLASSPATH to include /stuff/java
B、put Poker.jar in directory /stuff/java,and set the CLASSPATH to include /stuff/java/*.jar
C、Put Poker.jar in directory /stuff/java,and set the CLASSPATH to include /stuff/java/Poker.jar
D、put Poker.jar in directory /stuff/java/games/cards,and set the CLASSPATH to include /stuff/java
E、put Poker.jar in directory /stuff/java/games/cards,and set the CLASSPATH to include /stuff/java/*.jar
F、put Poker.jar in directory /stuff/java/games/cards,and set the CLASSPATH to include /stuff/java/Poker.jar
-
What is the result?()
A、 Cat
B、 Dog
C、 Compilation fails.
D、 The code runs with no output.
E、 An exception is thrown at runtime.
-
Which can be used to encode charS for output?()
A、 Java.io.OutputStream.
B、 Java.io.OutputStreamWriter.
C、 Java.io.EncodeOutputStream.
D、 Java.io.EncodeWriter.
E、 Java.io.BufferedOutputStream.
-
Given that a static method doIt() in a class Work represents work to be done, what block of code will succeed in starting a new thread that will do the work? CODE BLOCK a: Runnable r = new Runnable() { public void run() { Work.doIt(); } }; Thread t = new Thread(r); t.start(); CODE BLOCK b: Thread t = new Thread() { public void start() { Work.doIt(); } }; t.start(); CODE BLOCK c: Runnable r = new Runnable() { public void run() { Work.doIt(); } }; r.start(); CODE BLOCK d: Thread t = new Thread(new Work()); t.start(); CODE BLOCK e: Runnable t = new Runnable() { public void run() { Work.doIt(); } }; t.run();
A、Code block a.
B、Code block B.
C、Code block c.
D、Code block d.
E、Code block e.
-
ClassOne.java: 1. package com.abe.pkg1; 2. public class ClassOne { 3. private char var = ‘a’; 4. char getVar() { return var; } 5. } ClassTest.java: 1. package com.abe.pkg2; 2. import com.abc.pkg1.ClassOne; 3. public class ClassTest extends ClassOne { 4. public static void main(String[] args) { 5. char a = new ClassOne().getVar();6. char b = new ClassTest().getVar(); 7. } 8. } What is the result?()
A、 Compilation fails.
B、 Compilation succeeds and no exceptions are thrown.
C、 An exception is thrown at line 5 in ClassTest.java.
D、 An exception is thrown at line 6 in ClassTest.java.