package net.elaina.a01oopextensdemo2;
public class Test {
public static void main(String[] args) {
//利用空参构造创建子类对象
Zi z1 = new Zi();
z1.ziShow();
}
}
class Fu {
String name = "Fu";
}
class Zi extends Fu {
String name = "Zi";
public void ziShow() {
String name = "ziShow";
System.out.println(name); //ziShow
System.out.println(this.name); //Zi
System.out.println(super.name); // Fu
}
}
package net.elaina.a01oopextensdemo3;
public class Test {
public static void main(String[] args) {
OverseasStudent s1 = new OverseasStudent();
s1.lunch();
}
}
class Person {
public void eat() {
System.out.println("吃米饭,吃菜");
}
public void drink() {
System.out.println("喝开水");
}
}
//留学生
class OverseasStudent extends Person {
public void lunch() {
this.eat(); //吃意大利面
this.drink(); //喝凉水
super.eat(); //吃米饭,吃菜
super.drink(); //喝开水
}
public void eat() {
System.out.println("吃意大利面");
}
public void drink() {
System.out.println("喝凉水");
}
}
class Student extends Person {
public void lunch() {
//先在本类中查看eat和drink方法,就会调用子类的,如果没有,就会调用从父类中继承下来的eat和drink方法
this.eat(); //吃米饭,吃菜
this.drink(); //喝开水
//直接调用父类中的eat和drink方法
super.eat(); //吃米饭,吃菜
super.drink(); //喝开水
}
}
public class SharPei extends Dog{
@Override
public void eat() {
super.eat(); // 继承父类的功能
System.out.println("狗啃骨头");
}
}
标签:重构,java,void,drink,System,eat,访问,public,out From: https://www.cnblogs.com/elaina520/p/17835007.html构造方法的访问特点