public static void main(String[] args) {
try {
caller();
} catch (OtherException ex) {
System.out.println("Beach Time"); // Output: 3
}
}
private static void caller() throws OtherException {
System.out.println("Sunny"); // Output: 1
String str = "Beach Time";
if (str.equals("Beach Time")) { // it should be "Beach Time" and always TRUE then...
throw new OtherException("Thunderstorm");
System.out.println("Flooding"); // as exception throws never reach this part...
}
}
}
class OtherException extends Exception {
public OtherException(String str) { // Thunderstorm was sent but never use...
System.out.println("Shower"); // Output: 2
}
}
Here are the solutions, which confuses me
output line 1 : Sunny
output line 2: Shower
output line 3: Beach Time
public class OtherException extends Exception {
public OtherException(String str) {
System.out.println("Shower");
}
}
public class Quiz2 {
public static void main(String[] args) {
try {
caller();
} catch (OtherException ex) {
System.out.println("Beach Time");
}
}
public static void caller() throws OtherException {
System.out.println("Sunny");
String str = "Beach Time";
if(str.equals("Sunny"))
throw new OtherException("Thunderstorm");
System.out.println("Flooding");
}
}