• 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

Class and its method

 
Ranch Hand
Posts: 594
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ultimate aim of Class is ,I should contain Property and method who work on the property.




Is that is the case ,all the details to be passed to the class,should be go through Property only,for this getter and setter is enough ,so the method of the particular class should not take any input parameters and work on the property of the class only?

Ex:

Class A{

String one;
String two;

Void someMethod()
{

// work on the properties one and two
}

//here,Getter and setter for both properties one and two


}



 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your instance variable ONE and TWO will be null initially. getter/setter role is to fetch the current (this) value of these variables. someMethod() may take some input parameter say int i. Inside the method you may write if(i==0) {ONE = "hallo";} // here you have worked on your property based on some input parameter. So, initially calling getter would have fetched null. After calling someMethod(1), getter will fetch hallo.
 
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Getters and Setters are mutators; their only objective is setting and reading the state of an object.

2. Instance methods define or embody behavior/functionality for a particular class. For that they work on the state of object(i.e. properties). In a way, they try to make some meaning of the object state. These methods might need additional data to implement the behavior/functionality. Therefore, sometimes you need to pass them arguments. These arguments are/could be independent of object state and they maybe different for each invocation of the method.

3. Methods that work only with their arguments and independently of the Object state, should be declared static. Utility classes only have static methods with no properties and therefore no mutators.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic