这三题 ,如果你运行,你能说出答案吗?
1)
- public class Demo8 {
- public static void main(String[] args) {
- Test dq = Test.getInstance();
- System.out.println(dq.age +"---"+dq.hight);
- }
- }
- class Test
- {
- private static Test dq = new Test(10,100);
- public static int age ;
- public static int hight = 0;
- private Test(int age, int hight){
- this.age = age;
- this.hight = hight;
- }
- public static Test getInstance(){
- return dq;
- }
- }
复制代码
2)
- public class Demo8 {
- public static void main(String[] args) {
- Test dq = Test.getInstance();
- System.out.println(dq.age +"---"+dq.hight);
- }
- }
- class Test
- {
- private static Test dq = new Test(10,100);
- public static int age ;
- public static int hight = 0;
- private Test(int age, int hight){
- age = age;
- hight = hight;
- }
- public static Test getInstance(){
- return dq;
- }
- }
复制代码
3)
- public class Demo8 {
- public static void main(String[] args) {
- Test dq = Test.getInstance();
- System.out.println(dq.age +"---"+dq.hight);
- }
- }
- class Test
- {
- public static int age ;
- public static int hight = 0;
- private static Test dq = new Test(10,100);
-
- private Test(int age, int hight){
- this.age = age;
- this.hight = hight;
- }
- public static Test getInstance(){
- return dq;
- }
- }
复制代码
想清楚再回答哟~~~~~
还有大神,麻烦给解释一下~~~~ |
|