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

Why are the methods of the math class static?

0 Answers  


Is null a string or object in java?

0 Answers  


What is the relationship between a method?s throws clause and the exceptions that can be thrown during the method?s execution?

2 Answers  


What is parsing a string?

0 Answers  


What is sortedmap in java?

0 Answers  






System.out & System.in are final static data member of System class but we can change there reference through setOut() & setIn() method how...

2 Answers   FCS, TCS,


What is the difference between yielding and sleeping in java programming?

0 Answers  


What is the arguement of main method?

1 Answers  


What are functions in java?

0 Answers  


What is the use of 'super' keyword inside a constructor?

0 Answers   Flextronics, Thomson Reuters, Virtusa,


What is the difference between Object and Instance?

5 Answers   TCS,


What is structure of java heap? What is perm gen space in heap?

0 Answers  


Categories