123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Education >> View Article

Usage Of Super And Final Keyword

Profile Picture
By Author: Pradip Dwevedi
Total Articles: 3
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

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.

Syntax:

super(arg);

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
{
One()
{
System.out.println("Constructor of One class");
}
}

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

class Three extends Two
{
Three()
{
//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();
}
}
Output:
Constructor of One class
Constructor of Two class
Constructor of Three class

Super keyword is also to call the superclass overridden method.

Advantages:

->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.

Example:

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.

Example:

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

Example:

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: 361Word Count: 480See All articles From Author

Add Comment

Education Articles

1. How Chandigarh's Growing Business Ecosystem Is Supporting Business Analytics Careers
Author: Anusha

2. Oscp Certification Guide: Exam, Cost, Training, And Career Value
Author: Passyourcert

3. How To Pass The Asis Cpp Exam On Your First Try: Training Tips & Strategies
Author: Passyourcert

4. Top Things To Consider Before Choosing An Online Bca Course
Author: Grass Solution

5. Hair Growth Clinic In Anna Nagar – Advanced Solutions For Healthy And Strong Hair
Author: MAHESH

6. Who Is Eligible For An Honorary Doctorate?
Author: UniversityGuru

7. What Is Search Engine Optimization? Everything You Need To Know About Seo In 2026
Author: Rohit Shyam

8. Invisalign In Velachery – The Modern Way To Straighten Your Teeth Comfortably
Author: ivar

9. Digital Smile Design In Chennai – The Future Of Personalized Cosmetic Dentistry
Author: ivar

10. Cosmetic Smile Design In Chennai – Transform Your Smile With Advanced Cosmetic Dentistry
Author: ivar

11. Ai Agents With N8n Training | Ai Agents Course Online
Author: Vamsi Ulavapati

12. Agentic Ai With Copilot Studio Online Training | Agentic Ai
Author: Visualpath

13. Azure Data Engineer Training Online | Course In Ameerpet
Author: naveen

14. Is Bicsi Data Center Design Consultant Dcdc Certification Worth It In 2026?
Author: Passyourcert

15. Join Nda Coaching With Schooling In Pune And Achieve Your Defence Dream
Author: Delhi Career Group

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