How does final modifier work?

Answer Posted / javamasque

Final in java is used to restrict user to change further. It is used in various context as below

Final variable
• As variable become final, its value will never be modified.
• The variables become read only variable forever.
• If final variable is static then it must be initialized at the time of declaration.
• A non-static final variable can be blank but must be initialized in constructor.
• A local variable can be final.
• Final variables usually come with static key word as constant.

Final method
• As method become final, it never be override but be overload.
• A final method can be static and synchronized but never be abstract.
• As we are sure that the method implementation is complete and will never be override then we should make it final.

Final class
• A final class is complete class and will never be sub-classed.
• Final class helps to define immutable class.
• There are some final classes like String, Integer and other wrapper classes.

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how to split string in java?

660


What is a lightweight component?

598


What is difference between filereader and bufferedreader?

537


When will we prefer to use set and list in java and why?

550


What are the advantages of java over C++?

721






What is jee6?

540


Can we sort set in java?

542


Does it matter in what order catch statements for filenotfoundexception and ioexception are written?

512


Is it possible to instantiate the abstract class?

542


Is 0 true or false?

519


What is integers and example?

495


How to create a base64 decoder in java8?

560


Which is faster set or list in java?

534


What is a boolean in java?

581


What does math floor () do?

560