How does final modifier work?
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 |
why java does compile time polymorphism at run time ?
when to use ArrayList and when to use HashMap in webApplication.
What are actual parameters?
What is a class reference?
what are literals in java?
What is the difference between int and integer in java?
What is a percentage sign called?
long d =10;int i =0;i=d; /// is this possible? If d is very long number (10 digits or some thing) then?
what are upcasting and downcasting?
Explain class A{} class B{} class C{} all the three classes are saved in a single file name, what the name should i provide to the file ,in what file name should i run the program? Ple Explain
What is multi-catch block in java?
What are the different types of inner classes?