Skip to main content

Posts

Showing posts with the label Final

Super and Final keyword

  Super Keyword      The super keyword in java is a reference varible which is use to refer immediate parent class instance variable . Super can use to invoke immediate parent class method and constructors also. 1. To Refer Instance variable of an immediate parent class:      We can use super keyword to access the data member or field of parent class. It is used if parent class and child class have same fields. For example, class Animal{   String color="white";   }   class Dog extends Animal{   String color="black";   void printColor(){   System.out.println(color); System.out.println(super.color); }   }   class TestSuper1{   public static void main(String args[]){   Dog d=new Dog();   d.printColor();   } } Output: black white 2. To Refer method of an immediate parent class:      The super keyword can also be ...