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

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -