I know String is a final class in java.lang, so like string class is is possible to append other classes with the plus (+) operator.
For example I have a Class:
public class Foo{
public int x;
public int y;
public Foo(int x,int y){
this.x=x;
this.y=y;
}
public Foo append(int x,int y){
return new Foo(this.x+x,this.y+y);
}
}
Now, is it possible to add two classes like this:
Foo a=new Foo(2,3),b=new Foo(3,4);
Foo c=a+b;
System.out.println(c.x+" "+c.y);
And get the output like this:
5 7
If yes, what more will I have to do and if no why?