public class K {
private int n;
public K(int n) { this.n = n; }
public String toString() { return "K(" + n + ")"; }
}
// ...
K k = new K(7);
System.out.println("Got " + k);What is printed?
- Acheck_circle
Got K(7)
- B
Compile-time error
- C
Got 7
- D
Got K
Explanation
String concatenation invokes toString on the object, producing "Got K(7)".