Take the 2-minute tour ×

Just a quick and easy question, I'm doing a small project/assignment for a course and I wonder if any of you could kindly point out where I'm going wrong here. The question states:

Write a new class called GeometricShape. Add a field of type Point called center to represent the geometric center of the shape.

Add a constructor to the GeometricShape class that takes in two int’s, which are used to initialize the center variable. Display the message “Constructing a GeometricShape”. Within the constructor, initialize the field center to a new Point object, using the two int’s that were passed in to the constructor.

Here is the code that I have managed to come up with so far (assume Point is Testing):

    public class Testing{
        public int x;
        public int y;

        Testing(int i, int k){
            i = x;
            k = y;
            System.out.println("Constructing a Point");

    class GeometricShape{
        Testing center;

            GeometricShape(int z, int v){

            System.out.println("Constructing a GeometricShape");
            center c = new Testing(z, v);


When I attempt the last line of code to get the error: 'Unknown class: 'center''.

So I'm having trouble initializing the field center to a new Testing(Point) object.



share|improve this question
center = new Testing(z, v); - is this what you are trying to do? center is a name of a variable, not a class. –  sashkello Oct 9 '13 at 23:35
add comment

1 Answer

up vote 0 down vote accepted

You should just be using

center = new Testing(z, v);

Since center is the name for the Testing instance.

Also, in your Testing(int, int) constructor, you have the assignments for x and y backwards.

share|improve this answer
This looks like it's fixed the issue, Thanks. I need to brush up on Java, I've really been slacking! –  Charlie Coplestone Oct 9 '13 at 23:41
Don't forget to change i = x; k = y; to x = i; y = k; –  bluewhile Oct 9 '13 at 23:44
add comment

Your Answer


