0
upcasting and downcasting
I am having the following method: //Number is an abstract class //I am passing an object as a 1.argument and the 2nd argument is the instanzvariable itself public Number addition(Number n) { Realnumb r=(Realnumb)n;//downcasting Number n=new Realnumb(a+r.a); } public String toString() { } Main method: Number n1=new Realnumb(3.0); Number n2=new Realnumb(5.0); System.out.println(n1.addition(n2)); The result should be 8.0. My question is how to call the "toString" method in the method "addition"? As I am having a method of type "Number", what should be the return value?
1 Réponse
0
Its better to specify full code or related full code.
Actually print the corresponding object. then It implicitly calls toString() function.
or you can call explicitly through object.