-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiple_classes_and_objects.java
More file actions
55 lines (51 loc) · 1.25 KB
/
Multiple_classes_and_objects.java
File metadata and controls
55 lines (51 loc) · 1.25 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package NPTEL1;
//class circle1
class Circle1{
double x,y; //coordinates of center
double r;// radius of circle
//method for circumference
double circumference() {
return 2*3.14159*r;
}
//method for area
double area() {
return (22/7)*r*r;
}
}
//another class Box
class Box{
double width;// width of the box
double length;//length of the box;
double height;//height of the box
//method of the class Box for area calculation
double area() {
double a;
a=(width*height+width*length+length*height)*2;
return a;
}
//method of the class Box to calculate the volume
double volume() {
double v;
v=length*height*width;
return v;
}
}
// main class
public class Multiple_classes_and_objects {
public static void main (String[]args) {
Circle1 c= new Circle1();//object of the class circle
Box b=new Box();//object of the class Box
//initialization of the both the objects
c.x=0.0;
c.y=0.0;
c.r=5.0;
b.length=6.0;
b.height=3.0;
b.width=5.0;
//print statement for answer
System.out.println("Circumference: "+c.circumference());
System.out.println("Area: "+c.area());
System.out.println("Area: "+b.area());
System.out.println("Volume: "+b.volume());
}
}