Java this and super operators

Java super and this operators

  • You can refer to the members of the same class using this reference operator.
  • You can refer to the members of the superclass for the class using super reference operator.
    Using super and this operator example:
    ...
    class Person {
      String name
      Person(String name) {
        this.name = name; // Sets the class name equal to the parameter name
        ...
      }
      void Initiate () {
        ...
      }
    }
    
    class Doctor extends Person {
    
      Doctor(String name, String specialty) {
        super(name); // executes the super-class constructor
        super.Initiate(); // executes the method in the super-class
      }
      ...
    }
    ...
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.