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 生女孩红包简短祝福语