Special Offer take any 4 courses for INR 21999.00*

Courses
0

What is the purpose of the final keyword in Java?

December 26, 2024

The final keyword in Java is a non-access modifier used to impose restrictions on variables, methods, and classes. Its main purposes include:
Final Variable:
When a variable is declared as final, its value cannot be changed once assigned. This is often used to create constants.
final int MAX_VALUE = 100; // Constant
Final Method:
A final method cannot be overridden by subclasses. This ensures the method’s behavior remains unchanged in derived classes.
class Parent {
final void display() {
System.out.println(“This cannot be overridden.”);
}
}

Leave a Comment

Drop a Query

Whether to upskill or for any other query, please drop us a line and we'll be happy to get back to you.

Drop a Query NEW

Request A Call Back

Please leave us your contact details and our team will call you back.

Request A Call Back

By tapping Submit, you agree to Cambridge infotech Privacy Policy and Terms & Conditions

Enquiry Now

Enquiry popup