Why is System.out.println(super) not permitted?
System.out.println(this);
This is OK and this.toString() is called and printed automatically.
Of course, instance variable is OK instead of this.
However, this and super can be used in same way as I know.
System.out.println(super);
So why does this fail? I think it’s supposed to call super.toString() implicitly.
I have read Java specification document, but I haven’t found the reason.
Implementing a standalone variant of
superthat breaks virtual method dispatch would be an extremely bad idea.Let’s think about it for a while.
Now, let us take your suggestion and suppose that
superis valid and does what you suggest; then we may write inDerived:Now, if I understood you, you suggest that the main function should print in order:
toString()fromDerived: “Derived”.Description()fromDerived: “Derived description”toString()fromBase: “Base”.Description()fromBase: It does not exist. And the two solutions I can think of leads to bigger problems:Derived: breaks consistency.In short, such a use of the word
superconceptually breaks object-oriented programming.