.
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
Output:
tought python
Learn java
Use of Super keyword with constructor
class Hod
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="Mandir whi banyenge";
}
class Upbjp extends Bjp
{
String slogan="Ram lala hum ayenge";
void Election ()
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();
}
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()
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();
}
}
teach();
super.teach();
}
}
class Test{
public static void main(String args[])
{
Students d =new Students();
d.display();
}
}
Output:
tought python
Learn java
class Hod
{
Hod()
Hod()
{
System.out.println("Learn java");}
}
class students extends Hod
}
class students extends Hod
{
Students()
Students()
{
super();
System.out.println("tought Python");
}
}
class Test
super();
System.out.println("tought Python");
}
}
class Test
{
public static void main(String args[])
public static void main(String args[])
{
Students d=new Students();
}
}
0 Comments