> Hi Julian, > > ich habe hier noch einige Fragen zum Übungsblatt 4. > > Mit welcher Begründung wird bei Aufgabe 1 bei //05 und bei //06 > > super.m2(); // 05 > ((A)this).m2(); // 06 > > B.m2 aufgerufen? Und nicht A.m2 ?? stop. Bei 05 wird A.m2 aufgerufen, das verwundert ja auch nicht, und bei 06 B.m2. Warum? Das sagt das Internet: "The essence of runtime polymorphic behavior With runtime polymorphism based on method overriding, the decision as to which version of a method will be executed is based on the actual type of object whose reference is stored in the reference variable, and not on the type of the reference variable on which the method is invoked." - http://www.developer.com/java/article.php/983081 this zeigt auf ein Objekt vom Typ B, auch dann, wenn this zum Typ A gecastet wird. Also wird B.m2() aufgerufen. Das gleiche gilt fuer 15 auch. a zeigt auf ein Objekt vom Typ B, wenn auch a selbst vom Typ A ist. Eine Frage verbleibt: Warum verhält sich 08, 09 nicht analog (A.m3, A.m3)? Das liegt daran, dass m3() static ist: "Static Binding Static binding is deciding at compile time which method to invoke. With static binding, the method that gets invoked is determined by the type of the reference. In Java, class methods (static methods) are statically bound. Dynamic Binding [= Late Binding = Runtime Polymorphism] Dynamic binding is deciding at run time which method to invoke. With dynamic binding, the method that gets invoked is determined by the class of the object. In Java, instance methods (with 3 exceptions) are dynamically bound. " - http://www.artima.com/javaseminars/modules/PolymorphInt/ oder auch: "Here, a is an object of class Ancetor and m1() is a static method defined in Ancestor class. Then even if at run time the object reference a contains the reference of any descendent class of Ancetor a.m1() will always call m1() static method in Ancestor class and not of any descendent." - http://www.artima.com/legacy/answers/Jul2001/messages/152.html HTH, Julian D.