-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExceptionDemo.java
More file actions
44 lines (43 loc) · 849 Bytes
/
ExceptionDemo.java
File metadata and controls
44 lines (43 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package chandana;
import java.util.Scanner;
class Father
{
int Fage;
Scanner input = new Scanner(System.in);
Father()
{
System.out.println("Enter father's age:");
Fage=input.nextInt();
}
}
class Son extends Father{
int Sage;
Scanner input = new Scanner(System.in);
Son()
{
System.out.println("Enter son's age:");
Sage=input.nextInt();
}
}
class WrongAgeException extends Exception
{
public WrongAgeException(String str) {
System.out.println(str);
}
}
class ExceptionDemo
{
public static void main(String args[]) throws WrongAgeException
{
Son s=new Son();
try {
if(s.Sage>=s.Fage)
throw new WrongAgeException("Exception:");
else
System.out.println("You have entered a Valid Age");
}
catch(WrongAgeException e) {
System.out.println(e + " SON'S AGE >= FATHER'S AGE");
}
}
}