public class Test {
public static void main(String[] args) {
Shape shape = new Circle();
System.out.println(shape.name);
/**
* 为什么输出是
* shape constructor
circle constructor
shape
this is circle
shape
*/
shape.printType();
shape.printName();
}
}
class Shape {
public String name = "shape";
public Shape(){
System.out.println("shape constructor");
}
public void printType() {
System.out.println("this is shape");
}
public static void printName() {
System.out.println("shape");
}
}
class Circle extends Shape {
public String name = "circle";
public Circle() {
System.out.println("circle constructor");
}
public void printType() {
System.out.println("this is circle");
}
public static void printName() {
System.out.println("circle");
}
}