-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance_2.java
More file actions
50 lines (38 loc) · 1.14 KB
/
inheritance_2.java
File metadata and controls
50 lines (38 loc) · 1.14 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
class Base{
public int data;
private String name;
Base(int x,String str){
data=x;
name=str;
}
// public void BaseDetails(){
// System.out.println("DATA: "+data); // // Making it in one child class show that we can access it in one call from main function
// System.out.println("name: "+name);
// }
public void getName(){
System.out.println("name: "+name);
}
}
class Child extends Base{
public int age;
private String school;
Child(int y,String str2,int x,String str){
super(x,str);
age=y;
school=str2;
}
public void ChildDetails(){
System.out.println("age : "+age);
System.out.println("school: "+school);
System.out.println("DATA: "+data);
super.getName();
// System.out.println("name: "+name); // //we cannot this private variable in main BASE class
}
}
public class inheritance_2 {
public static void main(String[] args) {
// Base b1=new Base(100,"rahul");
Child c1=new Child(100,"Utkarsh",50,"GD Goenka");
c1.ChildDetails();
}
}