Super keyword in Java.

Comments

  • mkCodingmkCoding Atlanta, GA

    you use the "super" keyword when you are referring to a parent class
    for example:

    //super-class to class Bike
    public class Vehicle{
    int speed =50;
    }
    
    //Bike is a subclass to Vehicle
    public class Bike extends Vehicle{
    void display(){
    //super keyword used to retrieve value or call method from parent class
    System.out.println(super.speed);
    }
    }
    

    "super" is only used when the current class you're in has a parent/super-class.
    hope this helps

  • Super keyword is used to refer the methods, Constructor and variable of the super class.

    It is used to implement the concept of "Method Overriding".

    When there is same method defined in base and subclass then method of subclass overrides the super class method. So, To call the method of superclass, we use super() keyword.

    For more Details Refer following link:

    java.meritcampus.com/t/114/Call-super-class-constructors?tc=mm217

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories