不知道怎么让地球诞生在第一个地球创建中下面

不知道怎么让地球诞生在第一个地球创建中下面

package com.test;

import com.singleton.Earth;

public class Test2 {
	
	static {
		System.out.println("第一个地球创建中。。。。");
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Earth one = Earth.gete();
		Earth two = Earth.gete();
		Earth three = Earth.gete();
		
		
		
		System.out.println("第二个地球创建中。。。。");
		
		System.out.println("第三个地球创建中。。。。");
		
		System.out.println("问:三个地球是同一个么?");
		System.out.println(one);
		System.out.println(two);
		System.out.println(three);
		System.out.println(one==two);
		System.out.println(two==three);
	}

}
package com.singleton;

public class Earth {
	// 定义私有构造方法,并在构造方法中打印输出“地球诞生”
	private Earth() {
		System.out.println("地球诞生");
	}
	// 定义私有静态类对象并完成实例化
	private static Earth e = new Earth();	
	
	// 定义公有静态方法返回类内的私有静态对象
	public static Earth gete() {
		return e;
	}
}

只能这样 = =

正在回答 回答被采纳积分+1

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

3回答
好多可乐 2017-08-19 23:25:19

是要放在下面啊

喜欢做梦的鱼 2017-07-05 18:20:27

不可能啊,你在main方法里面,先输出“第一个地球创建中。。。。”,然后再通过单例方法获取地球对象。而且,老师留的参考代码块的样式也是这样的,http://img1.sycdn.imooc.com/climg//595cbd670001301611380506.jpg你是不是写错位置了。

喜欢做梦的鱼 2017-07-05 17:17:34

你把Test类中静态块里的“第一个地球创建中。。。。”放在main方法中就可以了。可以试一下。

  • 提问者 像云像雨像云 #1
    放进去地球诞生在上面 所以我才在上面做了一个静态代码块
    2017-07-05 17:35:16
  • 好帮手慕珊 回复 提问者 像云像雨像云 #2
    按老师那种方式修改,确实可以输出效果图中的效果的
    2017-08-20 12:13:55
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

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