-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.java
More file actions
43 lines (40 loc) · 965 Bytes
/
Copy pathInterface.java
File metadata and controls
43 lines (40 loc) · 965 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
import java.util.Scanner;
interface Roundshape
{
final double pi=3.14;
abstract void findarea();
abstract void findvolume();
}
class sphere implements Roundshape
{
Double radius;
Scanner sc=new Scanner(System.in);
public void findarea()
{
System.out.println("Enter radius:");
radius=sc.nextDouble();
System.out.println("Area of sphere is "+4*pi*radius*radius);
}
public void findvolume()
{
System.out.println("Enter radius:");
radius=sc.nextDouble();
System.out.println("Volume of sphere is "+(4/3)*pi*radius*radius*radius);
}
}
class Abstract1
{
public static void main(String[] args)
{
sphere s=new sphere();
s.findarea();
s.findvolume();
}
}
/*
Interface must be implemented to define its abstract class
all methods in interface are abstract
all methods defined in child class must be public
all variables in interface should be final
interface does not have constructor
*/