Polymorphism uses runtime binding. You declare an object of a particular type
and instantiate it with a different type
which must be the same type or its subclass. You can only invoke methods which exist in the superclass, but methods are called from the
runtime type of the object
prints "method1 of subclass."
If there isn't an overridden method, then the superclass method is called. Remember a Subclass object "
IS-A" Superclass object. Everything the superclass does for anybody else (accessible methods), the subclass does too. So if you haven't overridden the method you will get "from superclass" printed out. Note what you have been told about access modifiers, too. Because your method isn't accessible to the subclass, it cannot be overridden in that subclass.