1、关于private方法的继承
1、被继承后 只能在父类调用 比如父类里psvm new子类 子类.私有方法 可以调用到
2、无法被子类重写
重写:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public class Parent{ public void print(){ System.out.println("parent"); }
public void use(){ this.print(); } }
public class Son extends Parent{ public void print(){ System.out.println("son"); }
public static void main(String[] args) { Parent son = new Son(); son.use(); } }
|
无法重写:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public class Parent{ private void print(){ System.out.println("parent"); }
public void use(){ this.print(); } }
public class Son extends Parent{ private void print(){ System.out.println("son"); }
public static void main(String[] args) { Parent son = new Son(); son.use(); } }
|
2、关于default
一种理解是权限修饰符,不使用权限修饰符的方法,默认权限级别为default 同包可见,但是不能用default关键字修饰
default关键字修饰在接口里的默认方法 实现此接口后 默认的成员方法(可以被重写),且该方法依旧为public权限 此处的default与权限修饰无关
1 2 3 4 5 6 7
| public interface Human { int getAge();
default String getStr() { return "default String"; } }
|