package chapter04;标签:Child1,name,System,50,面向对象,println,super,out From: https://www.cnblogs.com/heiqiushuai/p/17092058.html
public class Java12_Object_Extends_01 {
public static void main(String[] args) {
// TODO 面向对象 - Extends - 继承
// 如果父类和子类含有相同的属性,那么可以采用特殊的关键字进行区分
// super(上一级) & this(这一级)
Child1 c = new Child1();
//System.out.println(c.name);
c.test();
}
}
class Parent1{
String name = "zhangsan";
}
class Child1 extends Parent1{
String name = "lisi";
void test(){
System.out.println(super.name);
System.out.println(this.name);
System.out.println(name);
}
}