hello i have this script
public static void main(String[] args) {
Circle circle1= new Circle(1);
Circle circle2= new Circle(2);
///swappingggg
System.out.println("b4 swap: circle 1 is " + circle1.radius +
"circle2="+circle2.radius);
swap(circle1,circle2);
System.out.println("after swap: circle 1 is " + circle1.radius +
"circle2="+circle2.radius);
}
public static void swap(Circle x, Circle y){
System.out.println("b4 swap: x=" + x.radius + "y ="+ y.radius);
Circle temp = x;
x = y;
y = temp;
System.out.println("After swap: x=" + x.radius + " y = " +
y.radius);
}
}
i get the error messenges
chapter6/Test.java [8:1] cannot resolve symbol
symbol : constructor Circle (int)
location: class chapter6.Circle
Circle circle1= new Circle(1);
^
chapter6/Test.java [9:1] cannot resolve symbol
symbol : constructor Circle (int)
location: class chapter6.Circle
Circle circle2= new Circle(2);
^
2 errors
Errors compiling main.
Matt Humphrey - 02 Feb 2005 20:21 GMT
> hello i have this script
>
[quoted text clipped - 35 lines]
> 2 errors
> Errors compiling main.
The compiler is letting you know that it cannot find the constructor for
Circle which uses one int parameter. Are you sure Circle.class is available
to the compiler and has been compiled? Are you sure that it has a 1-int
argument constructor?
Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/
Mary Lewis - 02 Feb 2005 21:53 GMT
try this:
class Test {
public static void main(String[] args) {
Circle circle1= new Circle(1);
Circle circle2= new Circle(2);
///swappingggg
System.out.println("b4 swap: circle 1 is " + circle1.radius +
"circle2="+circle2.radius);
swap(circle1,circle2);
System.out.println("after swap: circle 1 is " + circle1.radius +
"circle2="+circle2.radius);
}
public static void swap(Circle x, Circle y){
System.out.println("b4 swap: x=" + x.radius + "y ="+ y.radius);
Circle temp = x;
x = y;
y = temp;
System.out.println("After swap: x=" + x.radius + " y = " +
y.radius);
}
}
class Circle {
public int radius;
public Circle(int radius)
{
this.radius = radius;
}
}
(note - that you won't see the effect of the swap take place in your main
class as the swap method will only swap its own local variables x an y)