• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

String and Final

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rancher,

Can someone explain the below mentioned scenarios in the detail?

Scenrio-1

Scenario-2

If String class is final class then why do we need to create explicitly a final String Instance for CONSTANT variables?

Thanks in advance.
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a difference between a class being final and a variable being final.

Final for a class means that it can't be subclassed. Nothing more, nothing less.
Final for a variable (local, instance field, static field) means that it can only can have its value set once - and never again. A final parameter is similar - it can only be assigned from the method call.


In your example, you first assign "Test" to the final variable name. That means that name can never get a new value, and that's just what you're trying to do afterwards.
 
reply
    Bookmark Topic Watch Topic
  • New Topic