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 - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -