请完成下列Java程序:首先建立一个类,包含2个私有成员变量,分别为int和double型,并提供公共方法setInt()和 setDouble()分别给这两个变量赋值和用toString()方法显示对象的私有成员变量的值,要求将这个类定义为Serializable,再创建这个类的持久对象,将对象写入名为ex3_2.data的文件中并显示对象的2个成员变量,最后从这个文件中读取这个对象并显示对象的2个成员变量。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:ex3_2: i=123 d=123.456ex3_2: i=123 d=123.456import java.io.*;public class ex3_2 implements Serializable {private int n3_2;private double d3_2;ex3_2() {n3_2 = 25;d3_2 = 12.23;}public void setDouble(double x) {d3_2 = x;}public void setInt(int x) {n3_2 = x;}public String toString() {return("ex3_2: i=" + n3_2 + "d=" + d3_2);}public static void main(String[] arg) {ex3_2 e1 = new ex3_2 );ex3_2 e2;e1.setInt(123);e1.setDouble(123.456);System.out.println(e1);try {FileOutputStream fos3_2 = new FileOutputStream("ex3_2.data");ObjectOutputStream oos3_2 = new ObjectOutputStream(fos3_2);________________;} catch(IOException ioe) {System.out.println(ioe);}try {FileInputStream fis3_2 = new FileInputStream("ex3_2.data");ObjectInputStream ois3_2 = new ObjectInputStream(fis3_2);________________;System.out.println(e2);}catch(10Exception ioe) {System.out.println(ioe);}catch(ClassNotFoundException cnfe) {System.out.println(cnfe);}}}

请完成下列Java程序:首先建立一个类,包含2个私有成员变量,分别为int和double型,并提供公共方法setInt()和 setDouble()分别给这两个变量赋值和用toString()方法显示对象的私有成员变量的值,要求将这个类定义为Serializable,再创建这个类的持久对象,将对象写入名为ex3_2.data的文件中并显示对象的2个成员变量,最后从这个文件中读取这个对象并显示对象的2个成员变量。

注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:

ex3_2: i=123 d=123.456

ex3_2: i=123 d=123.456

import java.io.*;

public class ex3_2 implements Serializable {

private int n3_2;

private double d3_2;

ex3_2() {

n3_2 = 25;

d3_2 = 12.23;

}

public void setDouble(double x) {

d3_2 = x;

}

public void setInt(int x) {

n3_2 = x;

}

public String toString() {

return("ex3_2: i=" + n3_2 + "d=" + d3_2);

}

public static void main(String[] arg) {

ex3_2 e1 = new ex3_2 );

ex3_2 e2;

e1.setInt(123);

e1.setDouble(123.456);

System.out.println(e1);

try {

FileOutputStream fos3_2 = new FileOutputStream("ex3_2.data");

ObjectOutputStream oos3_2 = new ObjectOutputStream(fos3_2);

________________;

} catch(IOException ioe) {

System.out.println(ioe);

}

try {

FileInputStream fis3_2 = new FileInputStream("ex3_2.data");

ObjectInputStream ois3_2 = new ObjectInputStream(fis3_2);

________________;

System.out.println(e2);

}catch(10Exception ioe) {

System.out.println(ioe);

}catch(ClassNotFoundException cnfe) {

System.out.println(cnfe);

}

}

}


相关考题:

请完成程序,首先由一个类simple实现Serializable接口,并有三个成员变量,分别为int型、double型和String型,可以用toString的方法显示这三个成员变量。在main方法中创建这个simple的持久对象,根据用户在命令行输入的三个参数来设定其中成员变量的值。然后,将这个对象写入名为TheSerial.data的文件中,并显示成员变量。最后从文件TheSerial.data中读出三个成员变量并显示出来。注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。import java.io.*;class TheSerial implements Serializable{private int intvalue;private double doublevalue;private String string;The Serial (){intvalue=123;doublevalue=12.34;string="Serialize Test";}public void setDouble(double d){doublevalue=d;}public void setInt(int i){intvalue=i;}public void setString(String s){string=s;}public String to String(){return("int="+intvalue+" double="+doublevalue+" string="+string);}}public class simple{public static void main(String[] args){The Serial e1=new TheSerial();TheSerial e2;try{e1.setInt(Integer.parseInt(args[0]));e1.setDouble(Double.parseDouble(args[1]));e1.setString(args[2]);}catch(Exception e){e1.setString(e.getMessage());}System.out.println(e1);try{FileOutputStream S=new FileOutputStream("TheSerial.data");ObjectOutputStream OS=new ObjectOutputStream(oS);______;}catch(IOException ioException){System.out.println (ioException.getMessage ());}try{FileInputStream iS=new FileInputStream("TheSerial.data");ObjectInputStream IS=new ObjectInputStream(iS);______;System.out.println(e2);}catch(IOException ioException){System.out.println(ioException.getMessage());}catch(ClassNotFoundException cnfException){System.out.println(cnfException.getMessage());}}}

下列叙述中,错误的是( )。A.Java中,方法的重载是指多个方法可以共享同一个名字B.Java中,用abstract装饰的类称为抽象类,它不能实例化C.Java中,接口是不包含成员变量和方法实现的抽象类D.Java中,构造方法可以有返回值

请完成以下程序,首先由一个类Example2_3实现Serializable接口,并有三个成员变量,分别为int型、double型和String型,可以用toString的方法显示这三个成员变量。在main方法中创建这个Example2_3的持久对象,根据用户在命令行输入的三个参数来设定其中成员变量的值。然后,将这个对象写入名为TheSerial.data的文件,并显示成员变量。最后从文件TheSerial.data中读出三个成员变量并显示出来。注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。import java.io.*;class TheSerial implements Serializable{private int intValue;private double doubleValue;private String string;TheSerial(){intValue = 123;doubleValue = 12.34;string = "Serialize Test";}public void setDouble(double d){doubleValue = d;}public void setInt(int i){intValue = i;}public void setString(String s){string = s;}public String toString(){return("int="+intValue+"double="+doubleValue+" string="+string);}}public class Example2_3{public static void main(String argv[]){TheSerial e1 = new TheSerial();TheSerial e2;try{e1.setInt(Integer.parseInt(argv[0]));e1.setDouble(Double.parseDouble(argv[1]));e1.setString[argv[2]);}catch(Exception e){e1.setString(e.getMessage{));}System.out.println(e1);try{FileOutputStream S = new FileOutputStream("TheSerial.data");ObjectOutputStream IS = new ObjectOutputStream(oS);______;}catch(IOException ioException){System.out.println(ioException.getMessage());}try{FileInputStream iS = new FileInputStream("TheSerial. data");ObjectInputStream IS = new ObjectInputStream(iS);______System.out.println(e2);}catch(IOException ioException){System.out.println(ioException.getMessage());}catch(ClassNotFoundException cnfException){System.out.println(cnfException.getMessage());}}}

下列程序在构造函数和析构函数中申请和释放类的私有成员,请完成该程序。class Myclas{int *x;public:MyClas(int n);~MyClas();};MyClas::MyClas(intn){【 】;}MyClas::~MyClas(){【 】;}

下列程序在构造函数和析构函数中申请和释放类的私有成员,请完成该类的实现。class Myclass {public:Myclass(int num);~ Myclass( );public:int *p;};Myclass: :Myclass( int hum) {【 】Myclass:: ~ Myelass( ) {【 】;}。

下列关于单目运算符++,叙述正确的是A.运算对象可以是任何变量和常量B.运算对象可以是char型和int型变量,但不能是float型变量C.可以是int型变量,但不能是double型和float型变量D.运算对象可以是char型,int型,float型和double型变量

3、系统提供的默认拷贝构造函数实现的是“浅拷贝”,下列关于浅拷贝的说法中正确的是()。A.当一个类中有指针成员变量时,浅拷贝有可能会导致一片内存被重复释放B.当一个类中有指针成员变量时,浅拷贝有可能导致一个对象中保存的数据不正确C.如果一个类中只有int型和double型的成员变量,则浅拷贝不会出现任何问题D.如果一个类中有一个成员变量是char型数组,则使用浅拷贝会存在问题

186、系统提供的默认拷贝构造函数实现的是“浅拷贝”,下列关于浅拷贝的说法中正确的是()。A.当一个类中有指针成员变量时,浅拷贝有可能会导致一片内存被重复释放B.当一个类中有指针成员变量时,浅拷贝有可能导致一个对象中保存的数据不正确C.如果一个类中只有int型和double型的成员变量,则浅拷贝不会出现任何问题D.如果一个类中有一个成员变量是char型数组,则使用浅拷贝会存在问题

类、对象的定义及类的成员函数、构造函数建立问题 建立类cylinder,cylinder的构造函数被传递了两个double值,分别表示圆柱体的半径和高度。用类cylinder计算圆柱体的体积,并存储在一个double变量中。在类cylinder中包含一个成员函数vol,用来显示每个cylinder对象的体积。