编程语言
首页 > 编程语言> > Java-13,static关键字

Java-13,static关键字

作者:互联网

  

public class Cat {
    private static int sid = 0;
    private String name;
    private int id;
    
    Cat(String name){
        this.name = name;
        id = sid++;
    }
    
    public void info(){
        System.out.println("My name is "+name+" No."+id);
    }
    
    public static void main(String[] args) {
        Cat.sid = 100;
        Cat mimi = new Cat("mimi");
        Cat pipi = new Cat("pipi");
        mimi.info();
        pipi.info();
    }
}

运行结果:

My name is mimi No.100
My name is pipi No.101

内存分析:

 

 

 

标签:13,Java,name,成员,Cat,static,mimi,pipi
来源: https://www.cnblogs.com/nyist0/p/12364684.html