Skip to content

Commit c32d687

Browse files
committed
Interface in Java
1 parent 8d20863 commit c32d687

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

interface.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import java.io.*;
2+
3+
interface shape
4+
{
5+
6+
public void printArea();
7+
}
8+
class rectangle implements shape
9+
{
10+
public void printArea() throws Exception
11+
{
12+
int l,b;
13+
DataInputStream d=new DataInputStream(System.in);
14+
System.out.println("enter the length");
15+
l=Integer.parseInt(d.readLine());
16+
System.out.println("enter the breadth");
17+
b=Integer.parseInt(d.readLine());
18+
19+
System.out.println("AREA OF RECTANGLE="+(l*b));
20+
}
21+
}
22+
class triangle implements shape
23+
{
24+
public void printArea() throws Exception
25+
{
26+
int l,b;
27+
DataInputStream d=new DataInputStream(System.in);
28+
System.out.println("enter the length");
29+
l=Integer.parseInt(d.readLine());
30+
System.out.println("enter the height");
31+
b=Integer.parseInt(d.readLine());
32+
33+
System.out.println("AREA OF TRIANGLE="+(0.5f*l*b));
34+
}
35+
}
36+
class circle implements shape
37+
{
38+
public void printArea() throws Exception
39+
{
40+
int l,b;
41+
DataInputStream d=new DataInputStream(System.in);
42+
System.out.println("enter the radius");
43+
l=Integer.parseInt(d.readLine());
44+
45+
46+
System.out.println("AREA OF CIRCLE="+(3.14f*l*l));
47+
}
48+
}
49+
class m
50+
{
51+
public static void main(String v[]) throws Exception
52+
{
53+
rectangle r=new rectangle();
54+
r.printArea();
55+
triangle t=new triangle();
56+
t.printArea();
57+
circle c=new circle();
58+
c.printArea();
59+
}
60+
}

0 commit comments

Comments
 (0)