Font Awesome Icons
Tutorial
Menu
Core Java
AWT
Swing
Servlet
JSP
JDBC
Spring
Hibernate
JAVA TUTORIAL
What is Java
History of Java
Features of Java
C++ vs Java
Hello Java Program
Program Internal
How to set path
JDK, JRE and JVM
Internal Details of JVM
Java Variables
Java Data Types
Unicode System
Operators
Keywords
CONTROL STATEMENTS
Java If-else
Java Switch
Java For Loop
Java While Loop
Java Do While Loop
Java Break
Java Continue
JAVA OBJECT CLASS
Java OOPs Concepts
Naming Convertion
Object and Class
Constructor
static keyword
this keyword
JAVA INHERITANCE
Inheritance(IS-A)
Aggregation(HAS-A)
JAVA POLYMORPHISM
Method Overloading
Method Overriding
super keyword
Instance Initializer block
final keyword
Runtime Polymorphism
Dynamic Binding
instanceof operator
JAVA ABSTRACTION
Abstact class
Interface
Abstract vs Interface
JAVA ENCAPSULATION
Package
Access Modifiers
Encapsulation
JAVA ARRAY
Java Array
Java Programs
JAVA TUTORIAL
What is Java
History of Java
Features of Java
C++ vs Java
Hello Java Program
Program Internal
How to set path
JDK, JRE and JVM
Internal Details of JVM
Java Variables
Java Data Types
Unicode System
Operators
Keywords
CONTROL STATEMENTS
Java If-else
Java Switch
Java For Loop
Java While Loop
Java Do While Loop
Java Break
Java Continue
JAVA OBJECT CLASS
Java OOPs Concepts
Naming Convertion
Object and Class
Constructor
static keyword
this keyword
JAVA INHERITANCE
Inheritance(IS-A)
Aggregation(HAS-A)
JAVA POLYMORPHISM
Method Overloading
Method Overriding
super keyword
Instance Initializer block
final keyword
Runtime Polymorphism
Dynamic Binding
instanceof operator
JAVA ABSTRACTION
Abstact class
Interface
Abstract vs Interface
JAVA ENCAPSULATION
Package
Access Modifiers
Encapsulation
JAVA ARRAY
Java Array
Java Programs
super keyword in Java
The super keyword refers to the objects of the immediate parent class. The use of super keyword is given below:
1)Use of super keyword to access the variables of parent class
class Superclass
{
int num = 100;
}
class Subclass extends Superclass
{
int num = 110;
void printNumber()
{
System.out.println(super.num);
}
}
public class Main3
{
public static void main(String args[])
{
Subclass obj= new Subclass();
obj.printNumber();
}
}
2)Use of super keyword to invoke the constructor of a parent class
class Shiv
{
Shiv()
{
System.out.println(“shiv jee”);
}
}
class Ganesh extends Shiv
{
Ganesh()
{
super();
System.out.println(“subclass constructor”);
}
}
public class Main5
{
public static void main(String args[])
{
Ganesh g=new Ganesh();
}
}
Note: super() is added in each class constructor automatically by the compiler if there is no super()
3)super can be used to invoke parent class method
class Shiva
{
void care()
{
System.out.println(“caring..”);
}
}
class Ganesh extends Shiva
{
void happy()
{
System.out.println(“happyness…”);
}
void pro()
{
System.out.println(“spritual…”);
}
void work()
{
super.care();
pro();
}
}
public class Main5
{
public static void main(String args[])
{
Ganesh g=new Ganesh();
g.work();
}
}
Hi, Welcome to etechvidya
Home
About Us
Tutorial