Skip to content

Commit 41d3141

Browse files
janvimam inheritance concept
1 parent 5c920e8 commit 41d3141

File tree

1 file changed

+235
-0
lines changed

1 file changed

+235
-0
lines changed

inheritance with superkey

+235
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
2+
class simplegeo
3+
{
4+
private String colour="white";
5+
// private java.util.Date dlcrated;
6+
private boolean filled;
7+
8+
9+
public simplegeo(boolean f){
10+
11+
this.filled=true;
12+
13+
}
14+
15+
16+
/* public simplegeo(String k)
17+
{
18+
this.colour=k;
19+
}*/
20+
21+
public boolean getbol()
22+
{
23+
return filled;
24+
}
25+
26+
public void setbol(boolean s)
27+
{
28+
this.filled=s;
29+
}
30+
31+
public String getString()
32+
{
33+
return colour;
34+
}
35+
public void setstring(String s)
36+
{
37+
this.colour=s;
38+
}
39+
40+
41+
/* public void setdate(java.util.Date d)
42+
{
43+
this.dlcrated=d;
44+
}
45+
public java.util.Date getdate()
46+
{
47+
return dlcrated;
48+
}*/
49+
50+
}
51+
52+
class circle extends simplegeo
53+
{
54+
55+
private double radius;
56+
57+
public circle(boolean f,int r){
58+
super(f);
59+
this.radius=r;
60+
61+
}
62+
63+
public double getrad()
64+
{
65+
return radius;
66+
}
67+
68+
public void setrad(double a)
69+
{
70+
this.radius=a;
71+
}
72+
73+
public double rarea()
74+
{
75+
return (radius*radius)*3.14;
76+
}
77+
78+
public double rperi()
79+
{
80+
return 2*radius;
81+
}
82+
}
83+
84+
class rectangle extends simplegeo
85+
{
86+
private int length;
87+
private int width;
88+
89+
public rectangle(boolean f,int l,int w)
90+
{
91+
super(f);
92+
this.length=l;
93+
this.width=w;
94+
95+
}
96+
97+
public int getlength()
98+
{
99+
return length;
100+
}
101+
102+
public void setlength(int x)
103+
{
104+
this.length=x;
105+
}
106+
107+
public int getwidth()
108+
{
109+
return width;
110+
}
111+
112+
public void setwidth(int y)
113+
{
114+
this.width=y;
115+
}
116+
117+
public int getarea()
118+
{
119+
return (length*width);
120+
}
121+
122+
public int getperirec()
123+
{
124+
return 2*(length+width);
125+
}
126+
127+
}
128+
129+
class square extends simplegeo
130+
{
131+
private int edge;
132+
133+
public square(boolean f,int ed)
134+
{
135+
super(f);
136+
this.edge=ed;
137+
}
138+
139+
public int getedge()
140+
{
141+
return edge;
142+
}
143+
public void setedeg(int t)
144+
{
145+
this.edge=t;
146+
}
147+
public int getsarea()
148+
{
149+
return edge*edge;
150+
}
151+
public int getsperi()
152+
{
153+
return 4*edge;
154+
}
155+
}
156+
157+
158+
class inheritance
159+
{
160+
161+
public static void main(String[] args)
162+
{
163+
//the main object is call name is simplegeo
164+
165+
System.out.println("the main class simplegeo \n");
166+
167+
simplegeo obj1=new simplegeo(false);
168+
//obj1.setstring("white");
169+
System.out.println("the now colour is "+obj1.getString());
170+
//obj1.setdate(31/3/15);
171+
//System.out.println("the new date is right now "+obj1.getdate());
172+
173+
// obj1.setbol(true);
174+
System.out.println("now,check the value of the it's filled or not and at least last we get our result "+obj1.getbol());
175+
176+
System.out.println("\n");
177+
178+
// --------------------------------
179+
180+
//the next object is call name is circle
181+
System.out.println("the second class circle \n");
182+
183+
circle obj2=new circle(true,12);
184+
//obj2.setrad(5.3);
185+
System.out.println("the radius value is currently is "+obj2.getrad());
186+
System.out.println("the area of the circle is "+obj2.rarea());
187+
System.out.println("the prime is that is "+obj2.rperi());
188+
189+
190+
//obj2.setbol(true);
191+
System.out.println("your object is filled or not "+obj2.getbol());
192+
obj2.setstring("blue");
193+
System.out.println("now, your object is filled with the colour "+obj2.getString());
194+
195+
196+
197+
System.out.println("\n");
198+
199+
//-----------------------------------
200+
System.out.println("the third class rectangle \n");
201+
202+
rectangle obj3 = new rectangle(false,12,14);
203+
// obj3.setlength(12);
204+
//obj3.setwidth(14);
205+
206+
System.out.println("the value of the length is "+obj3.getlength());
207+
System.out.println("the value of the width is "+obj3.getwidth());
208+
System.out.println("the area of this rectangle is "+obj3.getarea());
209+
System.out.println("the peri of this rectangle is "+obj3.getperirec());
210+
211+
obj3.setbol(false);
212+
System.out.println("your object is filled or not "+obj3.getbol());
213+
//obj2.setstring("blue");
214+
System.out.println("now, your object is filled with the colour "+obj3.getString());
215+
216+
System.out.println("\n");
217+
//-----------------------------------
218+
System.out.println("the third class rectangle \n");
219+
220+
square obj4 = new square(false,18);
221+
// obj4.setedeg(10);
222+
System.out.println("the value of the edge is "+obj4.getedge());
223+
System.out.println("the area of this rectangle is "+obj4.getsarea());
224+
System.out.println("the peri of this rectangle is "+obj4.getsperi());
225+
226+
//obj4.setbol(true);
227+
System.out.println("your object is filled or not "+obj4.getbol());
228+
obj4.setstring("red");
229+
System.out.println("now, your object is filled with the colour "+obj4.getString());
230+
231+
232+
System.out.println("\n");
233+
}
234+
}
235+

0 commit comments

Comments
 (0)