importjava.io.*;publicclassForestimplementsSerializable{privateTreetree=newTree();publicstaticvoidmain(String[]args){Forestf=newForest();try{FileOutputStreamfs=newFileOutputStream(”Forest.ser”);ObjectOutputStreamos=newObjectOutputStream(fs);os.writeObject(f);os.close();}catch(Exceptionex){ex.printStackTrace();}}}classTree{}Whatistheresult?()
A.Compilationfails.
B.Anexceptionisthrownatruntime.
C.AninstanceofForestisserialized.
D.AinstanceofForestandaninstanceofTreearebothserialized.
第1题:
finalclassTree{privatestaticStringtree="tree";StringgetTree(){returntree;}}classElmextendsTree{privatestaticStringtree="elm";publicstaticvoidmain(String[]args){newElm().go(newTree());}voidgo(Treet){Strings=t.getTree()+Elm.tree+tree+(newElm().getTree());System.out.println(s);}}结果为:()
A.elmelmelmelm
B.treeelmelmelm
C.treeelmtreeelm
D.编译失败
第2题:
从对象流中读取对象,请在下面横线处填写代码完成此程序。
import java.util. *;
import java. io. *;
public class UnSerializeDate
{
date d = null;
UnSerializeDate ( )
{
try
{
FileInputStream f1 = new FileInputStream("date.ser");
d = (Date) s. readobject ();
f1,close();
}
catch (Exceptin e)
{
e. printStackTrace ();
}
}
public static main(String args [] )
{
System.out.println("The date read is: "+ a.d.toString());
}
}
第3题:
本题读取用户输入的字符流,直到用户输入字符串quit后结束。
importjava.io.*;
public class javal{
public static void main(String[]args){
;
BufferedReader in;
ir=new InputStreamReader(System.in);
in=new BufferedReader(ir);
System.OUt.println("please input:");
while( ){
try{
String s=in.readLine();
System.out.println("echo:"+s);
if(S.equals("quit"))
;
)catch(Exception e){
}
}
}
}
第4题:
现有:
classTree{
privatestaticStringtree="tree";
StringgetTree(){returntree;}
}
classElmextendsTree{
privatestaticStringtree="elm";
publicstaticvoidmain(String[]args){
newElm().go(newTree());
}
}
voidgo(Treet){
Strings=t.getTree()+Elm.tree+tree+(newElm().getTree());
System.out.println(s);}
结果为:()
第5题:
本题提示输入年份,然后判断该年份是否为闰年。 importjava.io.*; public class javal{ public static void main(String[]args){ InputStreamReader ir; BufferedReader in; ir=new InputStreamReader(System.in); in=new BufferedReader(ir); int year=1900; System.out.print("请输入年份:"); try{ String s=in.readLine; ; } (Exception e){ } if( ) System.OUt.println(year+"是闰年"); else System.out.println(year+"不是闰年"); } }