-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractical23.java
More file actions
31 lines (30 loc) · 1.08 KB
/
practical23.java
File metadata and controls
31 lines (30 loc) · 1.08 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
31
// Write a program that defines a Circle class with two constructors. The first form accepts a double value that represents the radius of the circle. The second form accepts the integer radius of the circle and calculates the area of the circle
class circle{
double radius;
circle(double r){
radius = r;
}
circle(int r){
radius = r;
}
double area(){
return Math.PI * radius * radius;
}
double circumference(){
return 2 * Math.PI * radius;
}
void display(){
System.out.println("Radius: " + radius);
System.out.println("Area: " + area());
System.out.println("Circumference: " + circumference());
}
}
public class practical23 {
public static void main(String[] args) {
circle c1 = new circle(5.5); // Using the constructor that accepts a double value
circle c2 = new circle(7); // Using the constructor that accepts an integer value System.out.println("Circle 1:");
c1.display();
System.out.println("\nCircle 2:");
c2.display();
}
}