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 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短