Keyword Super is also used to use the members of superclass which are same as the members of subclass.In this case if we use that member it refers to the member of subclass.
Syntax:: super.member;
here member can be data member or method
Following code will illustrate the concept:
Code::
import java.util.*;
class Base
{
Scanner in=new Scanner(System.in);
int a,b;
Base()
{
System.out.print("Enter Value of a:");
a=in.nextInt();
System.out.print("Enter Value of b:");
b=in.nextInt();
}
void display()
{
System.out.println("A= "+a+" \nB= "+b);
}
}
class Derived extends Base
{
Scanner in=new Scanner(System.in);
int c;
Derived()
{
System.out.print("Enter Value of c:");
c=in.nextInt();
}
void display()
{ super.display();
System.out.println("C= "+c);
}
}
public class Inheritance
{
public static void main(String[] nt)
{
Derived ob2=new Derived();
System.out.println("Values are:");
ob2.display();
}
}
Output::
Syntax:: super.member;
here member can be data member or method
Following code will illustrate the concept:
Code::
import java.util.*;
class Base
{
Scanner in=new Scanner(System.in);
int a,b;
Base()
{
System.out.print("Enter Value of a:");
a=in.nextInt();
System.out.print("Enter Value of b:");
b=in.nextInt();
}
void display()
{
System.out.println("A= "+a+" \nB= "+b);
}
}
class Derived extends Base
{
Scanner in=new Scanner(System.in);
int c;
Derived()
{
System.out.print("Enter Value of c:");
c=in.nextInt();
}
void display()
{ super.display();
System.out.println("C= "+c);
}
}
public class Inheritance
{
public static void main(String[] nt)
{
Derived ob2=new Derived();
System.out.println("Values are:");
ob2.display();
}
}
Output::