You can place an if statement inside another if statement. This is called nesting, and it lets you check a second condition only after a first condition passes.
int age = 20;
boolean hasID = true;
if (age >= 18) {
if (hasID) {
System.out.println("Entry allowed");
} else {
System.out.println("Show your ID first");
}
} else {
System.out.println("Too young");
}
The inner if only runs when the outer condition is true. This avoids checking hasID for someone who is underage.
Don't nest more than or levels deep. Deeply nested code is hard to read and even harder to debug. If you find yourself at + levels, consider combining conditions with && or extracting logic into a method.