View RSS Feed

Java Object

Calling an Object's Methods

Rate this Entry
by , 04-26-2012 at 06:09 PM (520 Views)
Object reference can be used for invoking the object method. Simple names of method are appended to the object reference along with (.) dot operator. Within enclosing parentheses arguments are provided to the method. If any arguments are not required by the method empty parentheses shall be used.
Java Code:
Two methods are linked to Rectangle class: getArea() for the computation of the rectangular arear, & move() for chaning the origin of rectangle. CreateObjectDemo code is given to invoke 2 methods.
Java Code:
System.out.println("Area of rectOne: " + rectOne.getArea());
rectTwo.move(40, 72);
First statement will be invoking rectOne getArea() method and results are displayed. The 2nd line will be moving rectTwo as move() provides new object values origin.x & origin.y

Submit "Calling an Object's Methods" to Facebook Submit "Calling an Object's Methods" to Digg Submit "Calling an Object's Methods" to Submit "Calling an Object's Methods" to StumbleUpon Submit "Calling an Object's Methods" to Google