标签:person default extend 输出 public import 派生 port cat
为什么要重写?
特点:
例:
package com.wnaoii.oop.Demo05;
public class Person {
public void say() {
System.out.println("Person会说话!");
}
}
package com.wnaoii.oop.Demo05;
public class A extends Person {
@Override
public void say() {
System.out.println("A不但会说,还会唱、跳、Rep!");
}
}
package com.wnaoii.oop;
import com.wnaoii.oop.Demo05.Person;
import com.wnaoii.oop.Demo05.A;
public class Application {
public static void main(String[] args) {
Person person = new Person();
person.say();
A a = new A();
a.say();
}
}
输出:
Person会说话!
A不但会说,还会唱、跳、Rep!
标签:person default extend 输出 public import 派生 port cat
原文地址:https://www.cnblogs.com/WNAOII/p/14751029.html