Friday, October 6, 2017

super keyword in java
The super keyword in java is a reference variable which is used to refer immediate parent class object.
Whenever you create the instance of subclass, an instance of parent class is created implicitly which is referred by super reference variable.
Usage of java super Keyword
  1. super can be used to refer immediate parent class instance variable.
  2. super can be used to invoke immediate parent class method.
  3. super() can be used to invoke immediate parent class constructor.

The final keyword in java is used to restrict the user. The java final keyword can be used in many context. Final can be:
  1. variable
  2. method

  1. class
Java  final variable

If you make any variable as final, you cannot change the value of final variable(It will be constant).


Java final method


If you make any method as final, you cannot override it.

3) Java final class

If you make any class as final, you cannot extend it.


Is final method inherited?

Ans) Yes, final method is inherited but you cannot override it.


Can we declare a constructor final?

No, because constructor is never inherited.

No comments:

Post a Comment