How does final modifier work?



How does final modifier work?..

Answer / 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

More Core Java Interview Questions

What is run time allocation?

1 Answers   Fidelity,


What is final, finally, finalize?

1 Answers  


Which are different kinds of source code?

1 Answers  


what is the swingutilities.invokelater(runnable) method for? : Java thread

1 Answers  


what is net based application and its types

1 Answers  


When we serialize an object does the serialization mechanism saves its references too?

1 Answers  


how to open and edit XML file in Weblogic???

1 Answers   Symphony,


What if constructor is protected in java?

1 Answers  


can used Protected Class outside Function.?

1 Answers   HCL,


What is the difference between equals() and == in java?

0 Answers  


What is the immediate superclass of the Dialog class?

2 Answers  


What are uses of Hash Code?

2 Answers   Cognizant,


Categories