3-2编程练习

3-2编程练习

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
public class Earth {
    //定义私有构造方法,并在构造方法中打印输出“地球诞生”
    private Earth() {
        System.out.println("地球诞生");
    }
     //定义私有静态类对象并完成实例化
    private static    Earth earth = new Earth();
     //定义公有静态方法返回类内的私有静态对象
    public static Earth getEarth() {
        return earth;
    }
}


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好,练习完成的不错,很棒呢!继续加油!!

祝学习愉快~

  • 残泪 #1

    为啥复制到在线编辑器,不能运行呢

    2021-05-30 07:02:59
  • 同学你好,老师尝试在在线编辑器中运行,是可以正常运行的,比如

    http://img1.sycdn.imooc.com//climg/60b2f090098ebe1011000423.jpg

    同学的不可以是什么具体的报错吗,还麻烦同学将自己运行截图贴出,老师来尝试定位一下问题。

    祝学习愉快!

    2021-05-30 09:56:21
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码