Skip to content
Sharp

Core Java · interview question

Given a boolean 'isHoliday' and a 'customerType' string, how would you structure an if-else statement to give discounts only on holidays to 'VIP' customers?

Multiple choiceHardchapter-1-curatedpremiumcore-javaconditions-and-branching
java
boolean isHoliday = true;
String customerType = "VIP";
if (isHoliday) { if (customerType.equals("VIP")) { giveDiscount(); } }
Choose one answer
Answer and explanation

Correct answer

A. If (isHoliday) { if (customerType.equals("VIP")) { giveDiscount(); } }

Why

The correct approach is to check if it is a holiday first and then verify if the customer is a VIP. This ensures that discounts are given only when both conditions are satisfied.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →