Sunday, January 30, 2011

The 'final' keyword always confusing!!!

Nowadays, I am doing some stuffs in java, so, I am quite close to java. It is 12:56 AM, last day of Jan i.e Jan 31st!. I was about to go to bed to sleep, but I got something which is quite confusing for many programmers the keyword 'final'. Here are the points which will clearify you to some extent:

1) The final keyword can be used for classes, methods, variables, and arguments. (more confused!) wait I will clarify you.
2) First, let the final variables, the variables declared as final can be instantiated only ONCE!

3) Lets think about methods, lets guess what may be special if we make the methods final, it is related to inheritance. Those methods declared as final can not be overridden.

4) The arguments declared as final also can be initialized only once. (I have not checked it... so , don't believe until you check it out)

5) The final classes are certainly similar to sealed classes i.e the classes can not be inherited.

(I am going to elaborate this one when I have time to write sample code using final keyword for different cases and test the result. )

No comments:

Post a Comment