implements Serializable可序列化,可以把这个类压缩存储起来
Employee 意思是雇员
String name; int age; int salary;字符串姓名,整数年龄,整数工资,是雇员的属性
public Employee(String name, int age, int salary) {
this.name = name;
this.age = age;
this.salary = salary;
}是构造函数
public void print() {
System.out.println("Record for: "+name);
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("Salary: "+salary);
}是输出雇员信息
//导入io包
import java.io.*;
//类定义,继承于接口Serializabel(可序列化接口)
public class Employee implements Serializable {
// 成员变量name
String name;
// 成员变量age
int age;
// 成员变量salary
int salary;
// 构造函数,初始化3个成员变量
public Employee(String name, int age, int salary) {
this.name = name;
this.age = age;
this.salary = salary;
}
// 打印方法,按格式输出3个成员变量
public void print() {
System.out.println("Record for: " + name);
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Salary: " + salary);
}
}