Objects of the subclass can be assigned to the reference of the super class. Indeed that is a way of polymorphism in Java.
Super class references are eligible only to call the overridden methods that are present in the subclass. So when you try to call the output2() method defined in the subclass the compiler shows you the error. Because output2() does not overrides any super class method. You are just implementing it from the interface Interface
Sankar Vaiyapuri wrote:The Compiler must show error when the Object of SubClass is assigned to the Object of SuperClass.
Because in real time programs the memory needed for the Object of SubClass is always higher than the memory needed for
the Object of SuperClass.
You've got a misunderstanding there of how variables work in Java. Variables aren't a slot that needs to be big enough to hold the entire object. They're just a reference to an object that lives on the heap. And references are all the same size regardless of what they're pointing at. So there's no "physical" problem in assigning an object of a subclass to a superclass reference.