I came across this question in a Java exercise and I keep getting a memory address printed.
Write code for the following class;
public class MyClass
{
}
such that the printed result of:
MyClass cls = new MyClass("Test Class");
System.out.println(cls);
will be “Test Class”.
(You will need to write the whole class, and use a parameter in the constructor in your answer).
You need to override the
toString()method for the above to work, and add a constructor like this: