父类:
public class Subjects {
public void b() {
System.out.println("学科");
}
public void a(){
System.out.println("这是继承父类的方法:Subjects");
}
public void c() {
System.out.println("这是父类的数学");
}
public void d() {
System.out.println("这是父类的英语");
}
public void e() {
System.out.println("这是父类的体育");
}
}
语文子类:
public class Language extends Subjects{
@Override
public void b(){
System.out.println("这是重写子类的方法:语文");
}
public static void main(String[] args) {
Language language = new Language();// 子类引用指向自身对象
language.b();// 子类覆盖了父类方法,所以调用新方法
Subjects subjects = new Language();
subjects.a();
}
}
数学子类:
public class Math extends Subjects{
@Override
public void c(){
System.out.println("数学");
}
public static void main(String[] args) {
Math math = new Math();
math.c();
Subjects subjects = new Math();
subjects.a();
}
}
英语子类:
public class English extends Subjects {
@Override
public void c(){
System.out.println("英语");
}
public static void main(String[] args) {
English english = new English();
english.d();
Subjects subjects = new English();
subjects.a();
}
}
体育子类:
public class Physical extends Subjects {
@Override
public void d(){
System.out.println("体育");
}
public static void main(String[] args) {
Physical physical = new Physical();
physical.e();
Subjects subjects = new Physical();
subjects.a();
}
}