Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2005

Tip: Looking for answers? Try searching our database.

circle class

Thread view: 
Irlan agous - 02 Feb 2005 18:28 GMT
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)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.