3-2编程练习
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("第一个地球创建中。。。。");
Earth earth1 = Earth.getEarth();
System.out.println("第二个地球创建中。。。。");
Earth earth2 = Earth.getEarth();
System.out.println("第三个地球创建中。。。。");
Earth earth3 = Earth.getEarth();
System.out.println("问:三个地球是同一个么?");
System.out.println(earth1);
System.out.println(earth2);
System.out.println(earth3);
}
}public class Earth {
//定义私有构造方法,并在构造方法中打印输出“地球诞生”
private Earth() {
System.out.println("地球诞生");
}
//定义私有静态类对象并完成实例化
private static Earth earth = new Earth();
//定义公有静态方法返回类内的私有静态对象
public static Earth getEarth() {
return earth;
}
}118
收起
正在回答
1回答
同学你好,练习完成的不错,很棒呢!继续加油!!
祝学习愉快~
java工程师2020版
- 参与学习 人
- 提交作业 9410 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星