This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Class and its method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class and its method " Watch "Class and its method " New topic
Author

Class and its method

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
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


}



Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
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.
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

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.


[List of FAQs] | [Android FAQ] | [Samuh Varta]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class and its method
 
Similar Threads
normal class and java Bean
Property attrin JSP with beans
Collection in logic iterate
Problem with jsp:setProperty ... (long mail)
How to consolidate multiple get-methods into one?