-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperConstructor.java
More file actions
49 lines (44 loc) · 1.21 KB
/
Copy pathSuperConstructor.java
File metadata and controls
49 lines (44 loc) · 1.21 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
/**
* * This file is part of the Java Programming Lecture project.
* *
* * It demonstrates the concept of `super` keyword in Java.
* * The `super` keyword is a reference to the parent class object.
* * It can be used to access parent class methods and variables.
* *
* * This Java snippet illustrates:
* * - How the 'super' keyword accesses parent class constructor
* *
* @package II_Unit.This_Super
* @author Dr. S. Sampath Kumar
* @since 03-08-2025
* @version 1.0
*/
// package II_Unit.This_Super;
// parent class
class Parent3 {
// parent class constructor
Parent3() {
System.out.println("Hi I am Parent class constructor.");
}
}
// child class extending parent class
class Child3 extends Parent3 {
// child class constructor
Child3() {
// invoking parent class constructor
// constructor overriding
// super(); // Explicitly call superclass constructor - Polymorphism
System.out.println("Hi I am Child class constructor.");
super();
}
void print() {
System.out.println("Hello");
}
}
public class SuperConstructor {
public static void main(String[] args) {
// creating instance of child class
Child3 obj = new Child3();
obj.print();
}
}