问题

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");
    }
}

 

 
posted @ 2017-11-12 16:30  Mr.V  阅读(145)  评论(0编辑  收藏  举报