package org.westos_01_继承;
/*
* 对于方法重写的注意事项:
* 1)父类的中的成员方法被private修饰,那么子类不能重写父类中的私有的成员方法
* 2)如果父类中的成员是一个静态的,那么子类在重写的时候,必须也是静态的成员方法,否则有问题
* 3)子类的成员方法要重写父类的成员方法,访问权限不能更低,最起码跟父类的权限一致!
*
* */
class Father7{
public void show(){
System.out.println("show father....");
}
//私有的成员方法
private void method(){
System.out.println("method Father...");
}
public static void function(){
System.out.println("function father");
}
public void function2(){
System.out.println("function2 father");
}
}
class Son7 extends Father7{
//子类要重写父类的方法
public void show(){
System.out.println("show son.....");
}
// public void method(){
// System.out.println("method son....");
// }
public static void function(){
System.out.println("function son....");
}
public void function2(){
System.out.println("function2 son");
}
}
public class ExtendsDemo10 {
public static void main(String[] args) {
//创建子类对象
Son7 s = new Son7() ;
// s.method() ;
s.function() ;
s.function2() ;
}
}
/*
* 对于方法重写的注意事项:
* 1)父类的中的成员方法被private修饰,那么子类不能重写父类中的私有的成员方法
* 2)如果父类中的成员是一个静态的,那么子类在重写的时候,必须也是静态的成员方法,否则有问题
* 3)子类的成员方法要重写父类的成员方法,访问权限不能更低,最起码跟父类的权限一致!
*
* */
class Father7{
public void show(){
System.out.println("show father....");
}
//私有的成员方法
private void method(){
System.out.println("method Father...");
}
public static void function(){
System.out.println("function father");
}
public void function2(){
System.out.println("function2 father");
}
}
class Son7 extends Father7{
//子类要重写父类的方法
public void show(){
System.out.println("show son.....");
}
// public void method(){
// System.out.println("method son....");
// }
public static void function(){
System.out.println("function son....");
}
public void function2(){
System.out.println("function2 son");
}
}
public class ExtendsDemo10 {
public static void main(String[] args) {
//创建子类对象
Son7 s = new Son7() ;
// s.method() ;
s.function() ;
s.function2() ;
}
}