0% found this document useful (0 votes)
2 views

Programs Print Real

The document contains a Java program that verifies if a voter is at least 18 years old. If the age is below 18, it throws an IllegalAccessException with a message. The program also includes a try-catch block to handle exceptions and confirms the completion of age verification.

Uploaded by

abinam396
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Programs Print Real

The document contains a Java program that verifies if a voter is at least 18 years old. If the age is below 18, it throws an IllegalAccessException with a message. The program also includes a try-catch block to handle exceptions and confirms the completion of age verification.

Uploaded by

abinam396
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

import java.util.

Scanner;
class AgeVerify {
void vote(int age)throws IllegalAccessException{
try{
if(age<18){
throw new IllegalAccessException("you must be atleast 18 years old to vote");
}
else{
System.out.println("you can vote");
}
}
catch (Exception e){
System.out.println("EXCEPTION OCCURED:" + e);
}finally{
System.out.println("Finally age verification done");
}
}
}
public class Trycatch{
public static void main(String[]args) throws IllegalAccessException {
Scanner sc = new Scanner(System.in);
int age;
System.out.println("Enter the age of the voter:");
age = sc.nextInt();
AgeVerify av = new AgeVerify();
av.vote(age);
System.out.println("verification completed succesfully");
}
}

You might also like