niusouti.com

importjava.io.*;publicclassForestimplementsSerializable{privateTreetree=newTree();publicstaticvoidmain(String[]args){Forestf=newForest();try{FileOutputStreamfs=newFileOutputStream(”Forest.ser”);ObjectOutputStreamos=newObjectOutputStream(fs);os.writeObject

题目

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.


相似考题
更多“importjava.io.*;publicclassForestimplementsSerializable{privateTreetree=newTree();publicst ”相关问题
  • 第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.编译失败


    参考答案: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());

    }

    }


    正确答案:ObjeetInputStream s = new ObjectInputStream(f1 ); UnSerilizaDate a = new UnSerializeDate();
    ObjeetInputStream s = new ObjectInputStream(f1 ); UnSerilizaDate a = new UnSerializeDate();

  • 第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){

    }

    }

    }

    }


    正确答案:
    第1处:InputStreamReaderir第2处:true第3处:break【解析】第1处构造一个InputStreamReader对象,把从控制台输入的字节作为参数,构建一个读取数据用的InDutStreamReader流,读取字节将其解码为字符;第2处while条件为真,执行循环;第3处当输入的s中的内容为quit时,跳出循环。

  • 第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);}

    结果为:()


    参考答案:C

  • 第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+"不是闰年"); } }


    正确答案:
    第1处:year=Integer.parseInt(s)
    第2处:catch
    第3处:year%4= =0year%100 !=0 ||year%400= =0
    【解析】第1处是将String型的s转换成整型;第2处是捕获异常的catch子句,用来处理由try所抛出的异常事件;第3处是判断是否为闰年的条件,即能被4整除且不能被100整除的或能被400整除的就是闰年。