Saturday, 7 March 2015

SUPER KEYWORD IN JAVA

super keyword in java:

The super keyword in java is a reference variable that is used to refer immediate parent class object.
Whenever you create the instance of subclass, an instance of parent class is created implicitly i.e. referred by super reference variable.

Usage of java super Keyword

  1. super is used to refer immediate parent class instance variable.
  2. super() is used to invoke immediate parent class constructor.
  3. super is used to invoke immediate parent class method.

Example :


class A
{
    public A(int x,int y)
{
    System.out.println(x+y);
}
}
class B extends A
{
    public B(int a, int b)
{
    super(a,b);
}
   public static void main(String args[])
{
   B bb=new B(10,20);
}
}

Sample Output :  30



No comments:

Post a Comment