浏览 2387 次
锁定老帖子 主题:extends
该帖已经被评为新手帖
作者 正文
   发表时间:2007-01-10  
OO

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