123ArticleOnline Logo
Welcome to 123ArticleOnline.com!

ALL » Education >> View Article

Usage Of Super And Final Keyword

By Expert Author: Pradip Dwevedi

A superclass constructor must execute before a subclass constructor. So that the state and behaviour defined by the superclass may be correctly and completely initialized before a subclass constructor executes.

Java compiler assumes that the first line of every constructor is an implicit call to the default superclass constructor unless you explicitly use super().super keyword is used to explicitly invoke a superclass constructor. it must appear as the first statement of the constructor to ensure that the superclass constructor executes before the subclass constructor in java.



The above is the syntax for calling superclass constructor.arg is optional list of arguments of the superclass constructor. You cannot use both super() and this() at the same time in same constructor.

Example for calling super class constructor:

class One
System.out.println("Constructor of One class");

class Two extends One
//super will be inserted here by default
System.out.println("Constructor of Two class");

class Three extends Two
//super will be inserted here by default
System.out.println("Constructor of Three class");

class MainClass
public static void main(String args())
Three obj = new Three();
Constructor of One class
Constructor of Two class
Constructor of Three class

Super keyword is also to call the superclass overridden method.


->super keyword is used to refer immediate parent class instance variable
->super() is used to invoke immediate parent class constructor
->super is used to invoke immediate parent class method
This is an important topic in the SCJP (now known as OCJP) certification, and should be well understood by the aspirants.

Final Keyword:

final is a keyword or reserved word in java and can be applied to member variables, methods, class and local variables in Java. Once you make a reference final you are not allowed to change that reference and compiler will verify this and raise compilation error if you try to re-initialized final variables in java

final Variable:

Any variable declared as final either in block or method they cant be modified.final variables are by default read only.


public static final String var = "whizlabs";

var=new String(“SCJP”); // compilation error.

final method:

A java method with final keyword is called final method and it cannot be overridden in sub-class. You should make a method final in java if you think it’s complete and its behaviour should remain constant in sub-classes. Final methods are faster than non-final methods because they are not required to be resolved during run-time and they are bonded on compile time.


class One{
public final String call(){
return "This is from One";
class Two extends One{
public final String call(){
return "This is from Two"; //compilation error: overridden method is final

final Class:

Final class is complete in nature and cannot be sub-classed or inherited. Several classes in Java are final e.g. String, Integer and other wrapper classes


final class One{}
class Two extends One{} // compilation error :cannot inherit final class
This is also an important part of the SCJP 6 certification course however aspirants who are preparing for OCAJP certification course should also look into this topic.

Author of the article is associated with Whizlabs, the global provider of certification preparation course material for Java, Project Management, and CCNA.

Total Views : 65Word Count Appx. : 479See All articles From Author

Education Articles

1. How The Iron Program In Australia Helps Nurses
Author: Arvin Alindogan

2. Sibm Hyderabad: The Springboard To Success
Author: sukanta singha

3. Top Ways To Start A Nursing Career In Australia
Author: Catherine Roberts

4. Specialized Mba Programs: Spearheading The Phase Shift Among Conventional Management Degrees!
Author: Laxman Dadar

5. Learn More On The Best Nursery Petersfield Has!
Author: sylver

6. How To Select A Language Course In Delhi
Author: Discounts Gyan

7. Mba Syllabus, Top Mba Colleges
Author: coursesmba

8. How To Gain The Ibm C2070-981 Certification
Author: Alexa Bliss

9. Studying About C_epmbpc_10 Latest Certification Material
Author: Alexa Bliss

10. Why It Is Said That To Learn Seo And Smo From An Expert And What Benefits Do It Have?
Author: anil kumar

11. How Adobe Cq5 Will Be Helpful In Accelerating Your Career
Author: claireed

12. Introduction To Prince2® Foundation Certification
Author: Graspskills

13. Not Allowed In Lsat
Author: rokyfernandis12

14. What Is Lsat?
Author: rokyfernandis12

15. Avantika University: Spearheading The Shift In Design Centered Education!
Author: Gaurav Peshkar

Login To Account
Login Email:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: