public class Test {
public static void main(String[] args) {
Shape shape = new Circle();
System.out.println(shape.name);
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");
}
}
運行結果
shape constructor
circle constructor
shape
this is circle
shape
這兩個shape是咋輸出的
uj5u.com熱心網友回復:
static 方法是不依賴實體的,你創建的物件是shape 的參考型別,所以他會呼叫shape 類的方法轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/47820.html
標籤:Eclipse
上一篇:序號自增
下一篇:ajax檢查注冊頁面用戶是否重復
