In my previous polymorphism tutorials I discussed the principle of polymorphic method invocation. At runtime, the JVM determines which method to invoke based on the type of the object, not the type of the reference variable. Since polymorphism applies to instance methods, does polymorphism apply to instance variables? The answer is no, polymorphism does not apply to instance variables.
Can we override an instance variable just like we can override an instance method? Technically NO, but there is more to it. While it is true that subclasses inherit members of a superclass – and that includes accessible instance variables – simply declaring an instance variable in the subclass with the same type and name merely 'hides' the inherited superclass instance variable.
Auf dieser Seite können Sie das Online-Video Learn Java Programming - Polymorphism and Instance Variables Tutorial mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Daniel Ross 06 September 2015 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 929 Mal angesehen und es wurde von 13 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!