黑马程序员技术交流社区
标题:
怎么能编译通过,好多错误,求解决
[打印本页]
作者:
廿乙木
时间:
2014-8-24 22:17
标题:
怎么能编译通过,好多错误,求解决
//饿汉式
class duoxiancheng_15_3
{
private int mun =4;
private static final duoxiangcheng_15_3 s =new duoxiancheng_15_3();
private duoxiancheng_15_3();
public static duoxiancheng_15_3 mtget()
{
return s;
}
}
//懒汉式
class duoxianchengxx_15_3
{
private static duoxianchengxx_15_3 ss = null;
private int num = 5;
private duoxianchengxx_15_3();
public static duoxianchengxx myget()
{
if(ss==null)
ss = new duoxianchengxx_15_3();
return ss;
}
}
//创建一个线程
class duoxiancheng1 implements Runnable
{
public void run()
{
while(true)
{
System.out.println(duoxiancheng_15_3.mtget().mun);
}
}
}
class duoxianchengDemo_15_3
{
duoxiancheng1 t = new duoxiancheng1();
Thread t1 = new Thread(t);
t1.start();
while(true)
{
System.out.println(duoxianchengxx_15_3.myget().num);
}
}
复制代码
作者:
何艳梅
时间:
2014-8-24 23:05
//饿汉式
class duoxiancheng_15_3
{
private int mun =4;
private static final duoxiancheng_15_3 s =new duoxiancheng_15_3();
private duoxiancheng_15_3(){};
public static duoxiancheng_15_3 mtget()
{
return s;
}
}
//懒汉式
class duoxianchengxx_15_3
{
private static duoxianchengxx_15_3 ss = null;
private int num = 5;
private duoxianchengxx_15_3(){};
public static duoxianchengxx_15_3 myget()
{
if(ss==null)
ss = new duoxianchengxx_15_3();
return ss;
}
}
//创建一个线程
class duoxiancheng1 implements Runnable
{
public void run()
{
while(true)
{
//既然你设了num是私有的,这里就不能用罗
// System.out.println(duoxiancheng_15_3.mtget().num);
}
}
}
class duoxianchengDemo_15_3
{
public void fun() {
duoxiancheng1 t = new duoxiancheng1();
Thread t1 = new Thread(t);
t1.start();
while(true)
{
System.out.println(duoxianchengxx_15_3.myget());
}
}
}
作者:
杨列振
时间:
2014-8-25 10:49
把报的错帖上来。
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2