java 函数 引用_java中如何在主函数里引用类的方法中的变量?

我是一名java初学者,今天下午写了个程序是这样的:importjava.util.*;publicclassTestPoint{publicstaticvoidmain(String[]args){MyThreadthread=newMyThread();thread.start();try{...

我是一名java初学者,今天下午写了个程序是这样的:

import java.util.*;

public class TestPoint

{

public static void main(String[] args)

{

MyThread thread= new MyThread();

thread.start();

try{Thread.sleep(10000);}

catch(InterruptedException e){}

thread.boot=false;

Thread.sleep(10000);

thread.in

}

}

class MyThread extends Thread

{

Boolean boot=true;

public void run()

{

Boolean boot=true;

while(boot)

{

System.out.println("==="+new Date()+"===");

try{

sleep(1000);

}

catch(InterruptedException e)

{

return;

}

}

}

}

编译时cmd显示找不到符号thread.boot=false;

我想是因为我把boot这个变量放在了Mythread类的run方法中的缘故。

我把run方法中对布尔值boot的定义语句放到了run方法的外面,编译就能通过了。

所以现在我想问,如果我就是想把boot变量在run方法中定义,我在主函数中不能通过thread.boot这种方式引用该变量,那么,我该通过什么方式引用该变量呢?

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值