This commit is contained in:
JinalShah31 2019-10-31 23:41:14 +05:30
parent 791294d17b
commit f05eec5fea
2 changed files with 108 additions and 0 deletions

56
dmd.java Normal file
View File

@ -0,0 +1,56 @@
import java.util.*;
class area
{
void display()
{
System.out.println("Area");
}
}
class triangle extends area
{
Scanner sc = new Scanner(System.in);
int b,h;
void display()
{
System.out.println("Enter base & height:");
b = sc.nextInt();
h = sc.nextInt();
System.out.println("Area of triangle:"+(0.5*b*h));
}
}
class circle extends area
{
Scanner sc = new Scanner(System.in);
int r;
void display()
{
System.out.println("Enter radius:");
r = sc.nextInt();
System.out.println("Area of triangle:"+(3.14*r*r));
}
}
class dmd
{
public static void main(String[] args)
{
int ch;
area a = null;
Scanner sc = new Scanner(System.in);
System.out.println("1.Triangle\n2.Circle\nEnter Choice:");
ch = sc.nextInt();
switch(ch)
{
case 1:
a = new triangle();
break;
case 2:
a = new circle();
break;
}
a.display();
}
}

52
excep.java Normal file
View File

@ -0,0 +1,52 @@
import java.util.*;
class InvalidAgeException extends Exception
{
InvalidAgeException(String s)
{
super(s);
}
}
/*class Testhrow
{
public static void validate (int age) throws InvalidAgeException
{
if(age < 18)
{
throw new InvalidAgeException("Not valid");
}
else
{
System.out.println("Valid");
}
}
}*/
class excep
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int age = sc.nextInt();
try
{
if(age < 18)
{
throw new InvalidAgeException("Not valid");
}
else
{
System.out.println("Valid");
}
}
catch (Exception e)
{
System.out.println("Exception Occurs");
}
finally
{
System.out.println("Rest of the code");
}
}
}