public class Employee { String name; int age; String designation; double salary; public Employee(String name) { this.name = name; } public void empAge(int empAge) { age = empAge; } public void empDesignation(String empDesig) { designation = empDesig; } public void empSalary(double empSalary) { salary = empSalary; } public void printEmployee() { System.out.println("名字:"+ name ); System.out.println("年龄:" + age ); System.out.println("职位:" + designation ); System.out.println("薪水:" + salary); } public static void main(String[] args) { Employee empOne = new Employee("RUNOOB1"); Employee empTwo = new Employee("RUNOOB2"); empOne.empAge(26); empOne.empDesignation("gao_ji"); empOne.empSalary(1000); empOne.printEmployee(); empTwo.empAge(21); empTwo.empDesignation("di_ji"); empTwo.empSalary(500); empTwo.printEmployee(); } }
名字:RUNOOB1
年龄:26
职位:gao_ji
薪水:1000.0
名字:RUNOOB2
年龄:21
职位:di_ji
薪水:500.0
public class Employee { String name; int age; String designation; double salary; public Employee(String name,int age) { this.name = name; this.age = age; } public void empDesignation(String empDesig) { designation = empDesig; } public void empSalary(double empSalary) { salary = empSalary; } public void printEmployee() { System.out.println("名字:"+ name ); System.out.println("年龄:" + age ); System.out.println("职位:" + designation ); System.out.println("薪水:" + salary); } public static void main(String[] args) { Employee empOne = new Employee("RUNOOB1",25); Employee empTwo = new Employee("RUNOOB2",22); empOne.empDesignation("gao_ji"); empOne.empSalary(1000); empOne.printEmployee(); empTwo.empDesignation("di_ji"); empTwo.empSalary(500); empTwo.printEmployee(); } }
名字:RUNOOB1
年龄:25
职位:gao_ji
薪水:1000.0
名字:RUNOOB2
年龄:22
职位:di_ji
薪水:500.0