package basicjavaday08;
public class InheritDemo {
static{
int st1 = 100;
String st2 = "hello static";
System.out.println(st1 + "****"+ st2);
}
public static void main(String[] args) {
int st1 = 223;
System.out.println("main st1 = " + st1);
System.out.println("*****************************");
Student434 st5 = new Student434();
st5.eat();
st5.eatStudent();
System.out.println("*****************************");
Student434.staticTest();
Student434.staticStudent434Test();
System.out.println("*****************************");
}
}
class Person{
int pe = 24;
static{
System.out.println("Person中的静态代码块");
}
{
System.out.println("Person 构造代码块");
}
public static void staticTest(){
System.out.println("Person 中的静态方法,用于测试类文件xxx.class的加载");
}
public Person(){
System.out.println("Person 构造方法");
}
public void eat(){
System.out.println("Person.eat");
}
}
class Student434 extends Person{
int pe = 28;
static{
System.out.println("Student434中的静态代码块");
}
{
System.out.println("Student 构造代码块");
}
public static void staticStudent434Test(){
System.out.println("这是从子类中的静态方法调用父类的静态方法");
staticTest();
}
public Student434(){
System.out.println("Student构造方法");
}
public void eatStudent(){
int pe = 32;
System.out.println("pe = " + pe);
System.out.println("pe = " + this.pe);
System.out.println("pe = " + super.pe);
super.eat();
}
}