继承的注意事项

来源:互联网 发布:网络视频存储方案 编辑:程序博客网 时间:2024/06/05 03:23
class Father
{
//私有成员变量不能继承
private int num = 10;
public int num2 = 20;

//私有方法不能继承
private void method(){
System.out.println(num);
System.out.println(num2);
}
public void show(){
System.out.println(num);
System.out.println(num2);
}
}
class Son extends Father
{
public void function(){
System.out.println(num2);


}
}
class jicheng
{
public static void main(String[] args){
Son s = new Son();
s.show();
s.function();
//s.method();//子类不能继承父类的私有成员方法
}
}
0 0
原创粉丝点击