• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

why getter and setter methods

 
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every field has setter and getter methods.what is happening in this methods
 
Ranch Hand
Posts: 174
Java ME Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, that was so detailed...
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where you set and get . tell me simply
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you already know that question's answer whats the point of asking. Secondly thats pure and basic common sense. If you want to ask from a design perspective then please elaborate on the question with the suitable alternative as to what do we use and why. Your question is too vague to be answered logically.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You question is not clear. Tell The Details
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not a servlet specific question. Posting such question in this forum wont attract good response.
 
Marshal
Posts: 71620
312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set and get methods allow access to private fields without "exposing" those fields. They may weaken encapsulation, but that can be minimised by putting controls in the methods.That version allows no control on which values are passed, nor controls on the use of the "f" reference after it has been returned.This second version ensures the value of i is always in a permitted range, as well as testing f for something or other. In either case, it throws an Exception with a nice error message so you can see what went wrong. You will also see that the returned f is cloned, so any manipulation of the clone does not affect this object.

There are different ways of handling such problems. For example, a copy constructor may be better than cloning. Note that i is a primitive, so there is no need to copy it when it is returned.

Agree with seetharaman venkatasamy that you ought to ask more details and with Samir Kureshi that you posted in the wrong place.
Aditya Keyal and Zandis Murāns: your responses are close to the line separating fair comment from rudeness.
 
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic