#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Homework question object oriented


    we are suppose to write a class called point which takes (x,y) and write a method in the class which takes in the parameters of another point and subtract it with the point from the class so i was wonder if i could make the 2 object subtract each other and if it could what the syntax would be or will i have to use variables and store the value from object 1 and object 2
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    74
    Rep Power
    18
    Originally Posted by henryzou
    we are suppose to write a class called point which takes (x,y) and write a method in the class which takes in the parameters of another point and subtract it with the point from the class so i was wonder if i could make the 2 object subtract each other and if it could what the syntax would be or will i have to use variables and store the value from object 1 and object 2
    If you are referring to operator overloading, i.e. for example:

    Code:
    Point a = new Point(1,1);
    Point b = new Point(2,3);
    Point c = a + b;
    That doesn't exist in Java (however it does in C#).

    Your code should be something like:
    Code:
    Point a = new Point(6,6);
    Point b = new Point(3,4);
    a.subtract(b);

IMN logo majestic logo threadwatch logo seochat tools logo