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);

}

  1. In this code, identify the catch block parameter and its type.
  2. What is the output if the input is 30?
  3. What is the output if the input is 19?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!