面向对象_方法重写的注意事项
2016-10-01 21:53
387 查看
/* 方法重写的注意事项: A:父类中私有方法不能被重写 因为父类私有方法子类根本就无法继承 B:子类重写父类方法时,访问权限不能更低 最好一致 C:父类静态方法,子类也必须通过静态方法进行重写 其实这个算不上方法重写,但是现像如此,至于为什么算不上方法重写,多态中理解 子类重写父类的时候,最好声明一模一样 */ class Father{ //private void show(){} /* public void show(){ System.out.println("show Father"); } */ void show(){ System.out.println("show Father"); } /* public static void mathod(){ } */ public void mathod(){ } } class Son extends Father{ //private void show(){} /* public void show(){ System.out.println("show Son"); } */ public void show(){ System.out.println("show Son"); } public static void mathod(){ } /* public void mathod(){ //Son 中的 mathod() 无法覆盖 Father 中的 mathod();被覆盖的方法为 static //public void mathod(){ //1 错误 } */ } class ExtendsDemo10{ public static void main(String[] args){ //创建对象 Son s = new Son(); s.show(); } }
相关文章推荐
- 面向对象_构造方法的重载及注意事项
- 面向对象_继承中构造方法的注意事项
- 22-JAVA面向对象-重写toString()与equals()方法
- java中重写Object类的equals方法和Hashcode方法的注意事项
- Java中重写equals方法的注意事项
- JS的window对象下的属性的方法和注意事项
- PHP面向对象之方法重写
- Android使用Parcelable传递对象方法及注意事项
- 关于在子类中重写父类的throws异常的方法的注意事项
- PHP基础----面向对象相关特性----12类的继承与方法重写
- 关于java调用对象,方法的注意事项
- 重写equals方法的注意事项
- Java中重写Object类的equals方法和hashcode方法的注意事项
- Android使用Parcelable传递对象方法及注意事项
- 5、面向对象以及winform的简单运用(方法重载、隐藏、重写与虚方法)
- 方法重写的注意事项
- Android使用Parcelable传递对象方法及注意事项
- C++ 与“类”有关的注意事项总结(十):类对象数组初始化(三种方法)
- 自定义View相关可以重写的方法及作用 需要注意的事项
- java学习之旅39--面向对象_12_继承_方法的重写