java - Learning basics about objects -


public class vector {     private final double deltax,deltay;      public vector(double deltax, double deltay) {         this.deltax = deltax;         this.deltay = deltay;      public vector plus(vector(a, b)){         return new vector(this.deltax+a,this.deltay+b);     } 

why not work when trying create method add new vector existing one? defining deltax horizontal component , deltay vertical.

you aren't using correct syntax. method should be:

public vector plus(vector other) {     return new vector(this.deltax + other.deltax, this.deltay + other.deltay); } 

that way, can pass vector instances method.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -