Hi there,
Sorry to say I've got another newbie question.....I'm working through Ivor Hortons "Beginning
Java 2 SDK 1.4 Edition". (Don't know if anyone has read this) I'm working through the exercises on "Defining Classes". Unfortunately, the exercises don't seem to come with any answers.
Basically, I've got a package called Geometry which contains two classes, Point and Line. A Line is made up from two Points. I'm creating a class called Rectangle, which is made up from two Points also (Top Left and Bottom Right). One of the exercises is to make a constructor method which creates a Rectangle from another Rectangle.
The problem is, I can't seem to access the Points public methods unless the class Rectangle is also part of the Geometry package by using: -
import Geometry.*;
I find this weird, because it obviously recognises the definition of the class Point for the Rectangle's private attributes.....I just can't access the methods (even though they are public).....the compiler complains about: -
(NetBeans error)
Cannot resolve symbol
symbol: method getX()
location: class Point
(JDK error)
Geometry/Rectangle.java [18:1] cannot resolve symbol
symbol : method getX ()
location: class Point
localPoint.setX(copyTopLeft.getX());
Now, this code works fine if the Rectangle class is also part of the Geometry package. Can someone tell me why this is the case and how I resolve it? Else using packages is going to be pretty useless if I cannot access the classes within the package properly from outside.
Thanks for any help.