-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance_4.java
More file actions
59 lines (46 loc) · 1.03 KB
/
inheritance_4.java
File metadata and controls
59 lines (46 loc) · 1.03 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
56
57
58
59
//inheritance
//ek class ki properties dusre class me inheritate ki ja sakti hai
//iske liye extends key word ka use hota hai
class base{
int x;
public void setx(int x)
{
this.x=x;
}
public int getx()
{
System.out.println(" i am in base and setting x");
return x;
}
public void printme()
{
System.out.println(" I am a constructor");
}
}
class derive
{
int y;
public void sety(int y)
{
System.out.println(" iam in derive and setting y");
this.y = y;
}
public int gety()
{
return y;
}
public void printme()
{
System.out.println(" I am a derived class");
}
}
public class inheritance_4 {
public static void main(String[] args) {
base b = new base();
// b.setx(4);
System.out.println(b.getx());
derive d = new derive();
d.sety(3);
System.out.println(d.gety());
}
}