`
happyanyday
  • 浏览: 81677 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

extends

    博客分类:
  • TIJ
 
阅读更多

1、子类方法的访问控制范围不能小于基类

exam:

基类:

public class grandpa implements family {

 public void eat(){
  System.out.println("grandpa eat!");
 }

 public void eat(String s) {
  // TODO Auto-generated method stub
  
 }

}
子类:

 class father extends grandpa {

 public void eat()
 {
  System.out.println("father eat");
 }
  void eat(String s){  //这就有错误 应该为 public void eat(String s){
  System.out.println(s);
 }
}

2、子类必须实现所有基类(或者叫父类,超类)的方法;

3、子类可以重写父类的方法;

4、子类可以添加其他的方法来完成特性功能。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics