This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
With that said, isn't it also possible to not use it at all? I have to hand write objects, so I would like to correct myself beforehand.
Yes its not necessary to use method.
- A method generally defines the subpart of the functionality what you are trying to achieve by writing a class.
- In method you can write the 'code' which is going to get reused.
Lets say you have a class Horse, it has code to "walk" written inside a method walk().
So every time you have to make the Horse walk you will not write the code to make it 'walk' instead you will call the method walk() where the code is already written.
Joined: Feb 24, 2011
Thanks that helped. It now leaves me to my last question what is the order or how do I properly use dot operators for any occasion. For some reason this is not getting into my brain. (classes,method,objects)
The dot is to access a member of a class (a member variable or a method).
object.method() means: call the method named "method" on the object that the variable named "object" refers to.
Note that "class" is a special property of objects that returns the java.lang.Class object of an object, which contains information about the class that the object belongs to.
object.method.class means: get the java.lang.Class of the member variable named "method" of the object that the variable named "object" refers to. (Note that this line of code will not work if "method" is actually a method - it will only work if "method" is a member variable).