-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathj40Inheritace.java
More file actions
43 lines (33 loc) · 1.01 KB
/
j40Inheritace.java
File metadata and controls
43 lines (33 loc) · 1.01 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
class Base{
int x , y;
public void value_set (int a , int b){
// Constructor
x = a;
y = b;
}
public int value(){
return x+y;
}
}
class Parent extends Base{
public int value(){
// if same name function in both class it executes own class meetheod
return x;
}
public int value_xy(){
return x*y;
}
}
public class j40Inheritace{
public static void main(String[] args){
Base baseClass = new Base();
Parent Exten_Parent = new Parent();
// features on Base class copy to Parent Class
// set values in Parent class
Exten_Parent.value_set(10,45); // this is the metheod of base class
// add of both values
System.out.println(Exten_Parent.value()); // metheod present in base and parentboth so they use its own parent class metheod
// using parent class metheod
System.out.println(Exten_Parent.value_xy());
}
}