4 Replies - 422 Views - Last Post: 22 April 2011 - 09:34 PM Rate Topic: -----

#1 BJT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 14-November 10

"super" keyword

Posted 21 April 2011 - 09:19 PM

Hello guys!

Right now, I'm having some problems with the "super" keyword in a class that my Java book is having me write. My book is a little old, so I'm not sure if "super" has changed since this book was written. However, I copied it exactly as it was out of the book

import java.awt.*;

public class Point3D
{
	public int z;

	public Point3D(int x, int y, int z)
	{
		super(x,y);
		this.z = z;
	}
	public void move(int x, int y, int z)
	{
		this.z = z;
		super.move(x, y);
	}
	public void translate(int x, int y, int z)
	{
		this.z += z;
		super.translate(x, y);
	}
}


On lines 9, 15, and 20 I am getting an error. On line 9, JCreator says "Object() in java.lang.Object cannot be applied to (int,int)" On 15 and 20, it says "cannot find symbol"

Thanks guys! I appreciate the help!

Is This A Good Question/Topic? 0
  • +

Replies To: "super" keyword

#2 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,619
  • Joined: 15-May 08

Re: "super" keyword

Posted 21 April 2011 - 09:29 PM

I think you may find that in order to utilise 'super' you need to have a class that extends another. In your case it would make sense that class Point3D extends Point

class Point {

  public Point(int x, int y) {
     this.x = x;
     this.y = y;
  }

  public void translate(int x, int y) {
    // .. code
  }

}



Then you have your Point3D
class Point3D extends Point {
  private int z;
  
  public Point3D(int x, int y, int z) {
     super(x,y);
     this.z = z;
  }

}


I suggest checking your textbook
Was This Post Helpful? 4
  • +
  • -

#3 BJT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 14-November 10

Re: "super" keyword

Posted 22 April 2011 - 08:42 AM

Thanks for the help, man. I'll be sure to try and add that stuff into my code as soon as I get the chance. Then, I'll let you know how it goes.

EDIT: Yep, worked perfectly. Thanks for the help!!

This post has been edited by BJT: 22 April 2011 - 08:47 AM

Was This Post Helpful? 0
  • +
  • -

#4 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 293
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: "super" keyword

Posted 22 April 2011 - 09:52 AM

Yep, super calls the constructor of parent classes.
Was This Post Helpful? 0
  • +
  • -

#5 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,619
  • Joined: 15-May 08

Re: "super" keyword

Posted 22 April 2011 - 09:34 PM

Glad it solved the issue BJT, post back anytime you have a question :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1