-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSphere.java
More file actions
30 lines (30 loc) · 1 KB
/
Copy pathSphere.java
File metadata and controls
30 lines (30 loc) · 1 KB
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
/*Write a program to define an abstract class “Roundshape” with one data member-
radius and a constant PI. Declare abstract methods findarea ( ) and findvolume ().
Define a sub class “sphere” and calculate the area and volume of a sphere object*/
import java.util.Scanner;
abstract class Roundshape{
public abstract double findarea();
public abstract double findvolume();
}
class Sphere extends Roundshape{
final double PI = 3.142;
private double radius;
public Sphere(){radius=1;}
public Sphere(double radius){
this.radius=radius;
}
public double findarea(){
return (4* PI* radius* radius);
}
public double findvolume(){
return (4/3*PI* radius*radius*radius);
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("please enter radius");
double radius=sc.nextDouble();
Sphere S = new Sphere(radius);
System.out.println("area of shpere is "+S.findarea());
System.out.println("volume of spehre id "+S.findvolume());
}
}