当前面跟后面的else if 都满足条件时,按顺序只执行前面的代码块。
package com.test;
public class TestIf {
public static void main(String[] args) {
int x = 2;
int y = 4;
if(x == 2) {
System.out.println("11");
} else if (y == 4) {
System.out.println("222");
} else {
System.out.println("no");
}
}
}
输出结果为:11