Hi,
This is one of the questions from Dan's mock exams
class B {
private
String name;
public B(String name) {this.name = name;}
public String toString() {return name;}
protected void finalize() {System.out.print(name);}
}
class H {
static B ba = new B("Ba");
static int i = 1;
static B m1(B b) {return b = new B("B" + i++);}
public static void main (String[] args) {
B x = m1(ba); m1(x);
System.out.println(", " + ba + ", " + x);
}}
The answers are given as ,Ba, B1 or B2, Ba, B1.
But my question is on the second call to method m1 with an argument x, the return type is of Object B. There should be a reference to B in the main function which can take the return value. calling just m1(x) will cause compiler error, as the function m1 returns an object.
Please clarify me if I am wrong.