[go: up one dir, main page]

0% found this document useful (0 votes)
18 views2 pages

Modifiers:: Thursday, April 16, 2020 8:11 AM

This document discusses the non-access modifiers in Java, specifically the final modifier. It states that final can be applied to classes, methods, and variables. For variables, a final variable can only be assigned a value once and cannot be changed thereafter, making it behave like a constant. For methods, a final method is inherited but cannot be overridden in a subclass. For classes, a final class cannot be subclassed or inherited from. The document provides examples and notes on using final with variables, methods, and classes in Java.

Uploaded by

NANDINI B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Modifiers:: Thursday, April 16, 2020 8:11 AM

This document discusses the non-access modifiers in Java, specifically the final modifier. It states that final can be applied to classes, methods, and variables. For variables, a final variable can only be assigned a value once and cannot be changed thereafter, making it behave like a constant. For methods, a final method is inherited but cannot be overridden in a subclass. For classes, a final class cannot be subclassed or inherited from. The document provides examples and notes on using final with variables, methods, and classes in Java.

Uploaded by

NANDINI B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Pg 1

Thursday, April 16, 2020 8:11 AM

Modifiers :
1. Access Modifiers
2. Non-Access Modifiers

Non-Access Modifiers :

1. static
2. final
3. abstract
4. synchronize
5. transient
6. volatile
7. strictfp

final :
final is a keyword, it is a non-access modifier.
In java we can use final modifier for class, methods and
variables.

Note:
We cannot use final for constructor or initializers(static and
non-static blocks)

1. final variables :
A variable prefixed with final modifier is known as
final variable.
➢ Global final variable
➢ local final variable

Note:
We can assign a value to a final variable only once, it cannot
be replaced or modified.
Hence final variable behaves like a constant

Note:
➢ for global final variable, initializing the variable with the help
of initializers is mandatory else we get Compile Time Error.

for ex refer, app25

Final Modifier Page 1


final Methods:
a method prefixed with final modifier is known as
final method.
A final method is inherited but it cannot be
overridden.

Note:
We cannot Override a final method from the sub class.

For ex refer, app25

Assignment :

1. What is the difference between private and final keywords.


2. What is the difference between final method and private
method.

final class :
A class prefixed with final modifier is known as final class.
A final class cannot be inherited.

for ex refer, app25

Final Modifier Page 2

You might also like