Java中使用非final变量的不可访问语句
下面是一个示例,其中我们将看到使用非final变量“-的unreachable语句
示例
class Demo_example {
int a = 2, b = 3;
void display_msg(){
while (a < b){
System.out.println("The first variable is greater than the second");
}
System.out.println("This is an unreachable statement");
}
}
public class Demo{
public static void main(String args[]){
Demo_example my_instance = new Demo_example();
my_instance.display_msg();
}
}输出结果
“The first variable is greater than the second” displayed infinitely
名为Demo_example的类,它定义了两个变量。然后定义一个名为“display_msg”的函数,并检查两个变量的相等性。相关消息将显示在控制台上。另一个名为“Demo”的函数包含主要函数,在其中创建了“Demo_example”类的实例。在此实例上调用“display_msg”,并且相关输出显示在控制台上。
热门推荐
10 医院探望朋友祝福语简短
11 毕业祝福语简短女朋友
12 春节虎年爸妈祝福语简短
13 儿童毕业祝福语 简短6
14 开工仪式横幅祝福语简短
15 孩子日常祝福语大全简短
16 清晨寄语诗句祝福语简短
17 结婚送亲认亲祝福语简短
18 虎年喝酒拜年祝福语简短