Question: Consider the following Java code: int age; try { System.out.println(Enter age: ); age = in.nextInt(); System.out.println(); if(age < 21) throw new Exception(Age must be more
Consider the following Java code:
int age;
try
{
System.out.println(Enter age: );
age = in.nextInt();
System.out.println();
if(age < 21)
throw new Exception(Age must be more than 21 years old);
System.out.println(Leaving try block.);
}
catch(Exception obj)
{
System.out.println(Age must be more than 21 years old);
}
- In this code, identify the catch block parameter and its type.
- What is the output if the input is 30?
- What is the output if the input is 19?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
