Results 1 to 3 of 3
  1. #1
    Ozzy21 is offline Member
    Join Date
    Aug 2014
    Posts
    2
    Rep Power
    0

    Default I am trying to extend Point

    I create Point3D.
    I want to use 3 coordinates "Points"
    I succesfully converted the building method and move,translate,setLocation methods in order to use them with 3 int coordinates.
    I failed with toString method.
    Any ideas?


    import java.awt.* ;
    public class Point3D extends Point {
    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);
    }
    public void toString (int x , int y , int z){
    this.z =z;
    super.toString(x,y);
    }
    public void setLocation(int x, int y , int z)
    {
    this.z=z;
    super.setLocation(x,y);
    }
    }

    I solved it by "stealing" point() code and had

    import java.awt.* ;
    public class Point3D extends Point {
    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);
    }
    public String toString() {
    return getClass().getName() + "[x=" + x + ",y=" + y +",z= " + z + "]";
    }

    public void setLocation(int x, int y , int z)
    {
    this.z=z;
    super.setLocation(x,y);
    }
    }

    Can you plz give me the reasong I couldn't just "extend" String()??
    Am completely noob and confused ;)

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,602
    Rep Power
    5

    Default Re: I am trying to extend Point

    Your original toString() method had a return type of void. And you weren't extending anything.
    Also, did you know that Point subclasses Point2D. If you don't want those extra methods
    then you may as well just create your own class. And you can improve on the original by
    making it immutable.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Ozzy21 is offline Member
    Join Date
    Aug 2014
    Posts
    2
    Rep Power
    0

    Default Re: I am trying to extend Point

    Thank you a lot Jim.
    After some hours of sleeps , things seem clear now.
    That was a silly question.Thank you again !!!

Similar Threads

  1. what really happens with extend and inheritance?
    By willemjav in forum New To Java
    Replies: 3
    Last Post: 02-11-2013, 11:51 AM
  2. to Extend or not to Extend
    By fatabass in forum New To Java
    Replies: 4
    Last Post: 12-21-2011, 04:28 PM
  3. Extend Jscroll
    By cowboy in forum New To Java
    Replies: 10
    Last Post: 12-13-2009, 08:07 PM
  4. extend a button
    By Omarero in forum New To Java
    Replies: 0
    Last Post: 03-25-2009, 06:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •