子类是否可以继承父类的私有属性和方法?

举例:

public class Employee {

private String name;

private double salary = 15000.00;

private Date birthDate;


public Employee(String n, Date Dob) {

name = n;

birthDate = Dob;

}

public Employee(String n) {

this (n,null);

}

}


public class Manager extends Employee {

private String department;

public Manager(String n, String d) {

super(n);

department = d;

}

}


结论:

子类可以继承父类所有的属性和方法(包括Private私有属性和方法),不过子类不可以直接访问到父类的Private属性和方法。



你可能感兴趣的:(Java)