/*
继承:
1.子类继承父类
2.java只支持单继承,不支持多继承,但是可以家族继承
3.父类在方法区创建完成后,子类创建时会带有父类标签(方便找到父类)
4.子类在堆中开辟空间时,父类的成员变量和私有变量也会一起创建
5.成员变量调用:本类中使用this;父类使用super
6.静态变量调用使用类名调用
7.相同变量名,调用时适用就近原则
*/
class Animal{
int x = 1;
static int y = 3;
public int eat(){
int x = 2;
//return x; //2
//return this.x; //1
return Animal.y; //3
}
}
public class ExtendsDemo {
public static void main(String[] args){
System.out.println(new Animal().eat());
}
}