The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

overload help

Posted by Alberto Marques on January 09, 2002 at 12:58 PM

I have four methods with the same name and when i compile it give me a
error.

thank you very much
Alberto Marques


the error :
MyRect.java:44: buildRect(java.awt.Point,java.awt.Point) in MyRect
cannot be aplied to (int,int,int,int)
rect.buildRect(25, 25, 50, 50);

the code :

import java.awt.Point;

class MyRect {
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;

MyRect buildRect(Point topLeft, Point bottomRight){
x1 = topLeft.x;
y1 = topLeft.y;
x2 = bottomRight.x;
y2 = bottomRight.y;

return this;
}

MyRect builRect(int x1, int y1, int x2, int y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;

return this;
}


MyRect builder( Point topleft, int w, int h ) {
x1 = topleft.x;
y1 = topleft.y;
x2 = ( x1 + w );
y2 = ( y1 + h );
return this;
}

void printRect(){
System.out.print("Myrect : <" + x1 + " , " + y1);
System.out.println(", " + x2 + " , " + y2 + ">");
}

public static void main(String args[]) {
MyRect rect = new MyRect();
System.out.println("Calling buildRect with cordinates 25,25 50,50:");

rect.buildRect(25, 25, 50, 50);

rect.printRect();
System.out.println("_________");
System.out.println("Calling buildRect w/points (10,10), (20,20):");

rect.buildRect( new Point(10,10), new Point(20,20) );

rect.printRect();
System.out.println("_________");
System.out.print("Calling buildRect w/1 point (10,10),");
System.out.println("width (50) and height (50)");

//rect.buildRect( new Point(10,10), 50, 50);

rect.printRect();
System.out.println("_________");
}
}





Replies:
  • Typo Kishori sharan January 09, 2002 at 4:23 PM (0)

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us