悬赏分:10 - 离问题结束还有 14 天 23 小时
Java程序设计
1. import java.util.*
2.
3. public class EmployeeTest
4. {
5. public static void main(String[] args)
6. {
7. // fill the staff array with three Employee objects
14. // raise everyone's salary by 5%
18. // print out information about all Employee objects
}
24. }
25.
26. class Employee
27. {
28. public Employee(String n, double s, int year, int month, int day)
37. public String getName()
42. public double getSalary()
47. public Date getHireDay()
52. public void raiseSalary(double byPercent)
58. private String name
59. private double salary
60. private Date hireDay
61. }
class Father {private int f1, f2
public Father(int x) {
f1 = x
}
public Father(int x, int y) {
// 和上面一个参数的构造方法做同样的 *** 作,包括赋值 f1=x
f1 = x
f2 = y
}
public void display() {
System.out.println("f1=" + f1 + "f2=" + f2)
}
}
class Son extends Father { // 继承类 Father
private int s1
private int s2
public Son(int x, int y) {
// 调用父类的构造方法,传递参数x
super(x)
s1 = y
}
public void display() {
// 调用父类的display()方法
super.display()
System.out.println("s1=" + s1 + "s2=" + s2)
}
}
public class Test {
public static void main(String args[]) {
Father f = new Son(5, 6)
f.display()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)