I am new to Java and want to ask this question: Why don't I have to use anonymous class' overrode method, but instead just use it's object to reach the overrode method?
I hope I made myself clear, but if not, I'd like to refer to the image below:
This is my anonymous class, it's inside a method called instanceMethod();
Here, I test this with my ClassTester.java class
My question is that even though I use System.out.println(demo);, I still get the same result, i.e.,
So this means that I don't need to use System.out.println(demo.toString());
Do you know the reasoning behind this? Does it work like a constructor?
Any help is appreciated.
Best.