-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuper_.java
More file actions
109 lines (79 loc) · 2.39 KB
/
super_.java
File metadata and controls
109 lines (79 loc) · 2.39 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<<<<<<< HEAD
// Parent Class
class Person {
String name = "Unknown";
// Parent Class Constructor
Person(String name) {
this.name = name; // this refers to current object
System.out.println("Parent Constructor Called");
}
void display() {
System.out.println("Name from Parent Class: " + name);
}
}
// Child Class
class Student extends Person {
int rollNo;
// Child Class Constructor
Student(String name, int rollNo) {
// Calling parent class constructor
super(name); // super calls parent constructor
this.rollNo = rollNo; // this refers to current class variable
System.out.println("Child Constructor Called");
}
void show() {
// Calling parent class method
super.display(); // super calls parent method
// Using this keyword
System.out.println("Roll No from Child Class: " + this.rollNo);
}
}
// Main Class
public class super_{
public static void main(String[] args) {
// Creating child object
Student s = new Student("Nidhi", 15);
System.out.println("\nStudent Details:");
s.show();
}
}
=======
// Parent Class
class Person {
String name = "Unknown";
// Parent Class Constructor
Person(String name) {
this.name = name; // this refers to current object
System.out.println("Parent Constructor Called");
}
void display() {
System.out.println("Name from Parent Class: " + name);
}
}
// Child Class
class Student extends Person {
int rollNo;
// Child Class Constructor
Student(String name, int rollNo) {
// Calling parent class constructor
super(name); // super calls parent constructor
this.rollNo = rollNo; // this refers to current class variable
System.out.println("Child Constructor Called");
}
void show() {
// Calling parent class method
super.display(); // super calls parent method
// Using this keyword
System.out.println("Roll No from Child Class: " + this.rollNo);
}
}
// Main Class
public class super_{
public static void main(String[] args) {
// Creating child object
Student s = new Student("Nidhi", 15);
System.out.println("\nStudent Details:");
s.show();
}
}
>>>>>>> 88d54c5 (hellooooo)