- class Single
- { private int num;
- public void setNum(int num)
- { this.num=num;
- }
- public int getNum()
- {
- return num;
- }
- Single(){}
- private static Single s =new Single();
- }
- class SingleDemo
- {
- public static void main (String[]args)
- {
- Single s1=new Single();
- Single s2=new Single();
- s1.setNum(30);
- System.out.println(s2.getNum());
- }
- }
复制代码 请问 类中有private static Single s =new Single();的语句,请问这个s是在方法区还是堆内存中? 这个程序总共创建了几个对象?谁介绍下创建的几个对象的先后顺序,说下创建这几个对象的先后步骤 |