Super keyword in java

.
What is super keyword ?
In java programming language super keyword is defined as the refrance variable that is used to refer parent class or base class object

Use of Super keyword with variable

class Bjp
{  
String slogan="Mandir whi banyenge";  
}  
class Upbjp extends Bjp
{  
String slogan="Ram lala hum ayenge";  
void Election ()
{  
System.out.println(slogan);
System.out.println(super.slogan);
}  
}  
class Results{  
public static void main(String args[]){  
Upbjp up=new Upbjp();  
Up.Election();  
}
}  

Output:
Ram lala hum ayenge
Mandir whi banyenge




Use of Super keyword with method

class Hod
{  
void teach()
{
System.out.println("Learn java");
}  
}  

class Students extends Hod
{  
void teach()
{
System.out.println("tought python");
}  

void display()
{
teach();  
super.teach();  
}  
}  

class Test{  
public static void main(String args[])
{  
Students d =new Students();  
d.display();  
}
}  


Output:
tought python
Learn java

Use of Super keyword with constructor
class Hod
{  
Hod()
{
System.out.println("Learn java");}  
}  
class students extends Hod
{  
Students()
{  
super();  
System.out.println("tought Python");  
}  
}  
class Test
{  
public static void main(String args[])
{  
Students d=new Students();  
}

Output:
Learn java
tought Python

Rules and regulations to declare super keyword in Constructor


Super keyword in java





Post a Comment

0 Comments