File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class and its method " Watch "Class and its method " New topic

Class and its method

jacob deiter
Ranch Hand

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


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

Joined: Oct 12, 2008
Posts: 1369

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:
subject: Class and its method
It's not a secret anymore!