• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When I must use Getters and Setters?

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

When I must use Getters and Setters? When I need to access any attribute and increment?

ex:

public class Account{
String name;
int id;

}

---------------------------
Class Manager{
Account a = new Account ();
a.name('André AS');
}


Do I need to you set and get for acess id attribute?

André AS
???

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see how this is Struts-specific.
 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Set and Get...
 
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:I don't see how this is Struts-specific.


I don't think it is.

André Asantos wrote:Do I need to you set and get for acess id attribute?


You won't, if the Account and the Manager classes are both in the same package, because "String name" and "int id" have default access modifier. So you can access "id" directly.

If your Account class contains only name and id, then you can make these as "private" and then have get and set methods for them.
 
reply
    Bookmark Topic Watch Topic
  • New Topic