-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructor_Maniac.java
More file actions
34 lines (30 loc) · 918 Bytes
/
Constructor_Maniac.java
File metadata and controls
34 lines (30 loc) · 918 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
class Circle
{
String Type;
static String Figure; //As it is static so if we initialize with one object reference then the value will be same for all the object references.
double radius; //here we have to initialize every time with different object references.
Circle(double radius)
{
this.radius=radius;
System.out.println("Area is :"+(radius*radius));
}
void show()
{
System.out.println("Radius was :"+radius);
}
}
public class Important {
public static void main(String[] args) {
Circle cc1 = new Circle(20);
cc1.Type="For object reference 1";
System.out.println(cc1.Type);
cc1.show();
Circle.Figure="Figure is same for all objects references";
System.out.println(Circle.Figure);
Circle cc2 = new Circle(10);
cc2.Type="For object reference 2";
cc2.show();
System.out.println(cc2.Type);
System.out.println(Circle.Figure);
}
}