I've created an object inside a method and inside main. I want the object inside of the method to be returned. I thought everything in Java was returned by reference not value, so I'm not quite sure how to do this.
public class Measurement
{
private int value;
private String units;
public static void main(String[] args)
{
Measurement a = new Measurement(2,"cm");
Measurement b = new Measurement(5,"cm");
Measurement c = new Measurement();
c = a.mult(b);
}
public Measurement mult(Measurement aObject)
{
Measurement c = new Measurement();
c.value = this.value * aObject.value;
c.unit = this.unit;
return c;
}
}