• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using of final keyword

 
Rahul Noel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


My Question what is the difference between line no. 6 & 7.I mean both are working what is the purpose of the using final in line 6. please let me know.
 
Ivan Vrtacnik
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Final is a keyword that is relevant to inheritance, not behaviour of the variable in the given class.

It means that the final variable cannot be inherited by children of this class.
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can modify the status of the object which you created in line 6 eventhough you are using final keyword.

the main use of final is you cannot use that reference variable to point to another object.that means reference can not be changed.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ivan Vrtacnik
----
Final is a keyword that is relevant to inheritance, not behaviour of the variable in the given class.


Inheritance has nothing to do with the given code. Reference variable "test" is local to main method. Here it means you cannot assign any object to "test" reference variable. But you can do this later in the code...



but not with test reference because it's final and you cannot re-assign anything to it once you assign an object this case .
 
Rahul Noel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
Thanks for your quick response and clarifying my doubt.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic