1.属性只能说覆盖,不能说重写
2.子类可以有和父类一模一样的方法这叫重写。
3重载与重写有什莫区别
重载overload:
在一个类中拥有方法名相同形参不同的方法的现象叫做重载
重写overread:
在两个类中子类对付类的方法进行重新编写这叫做重写
4.重写的注意事项:
1.不能改变形参列表。
2.不能改变返回值。
3.访问修饰符不能比之前从高
4.私有的方法不能被重写因为无法被继承。
public class chongxie {
public static void main(String[] args) {
Son2 s2= new Son2();
s2.show();
}
}
class Father2{
public void show() {
System.out.println("你好");
}
}
class Son2 extends Father2{
public void show() {
System.out.println("你好啊");
}
}