انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

Inheritance and Overriding Methods

الكلية كلية تكنولوجيا المعلومات     القسم قسم البرامجيات     المرحلة 2
أستاذ المادة احمد مهدي محمد سعيد الصالح       31/01/2016 20:34:23
Single Inheritance
• When a class inherits from only one class, it is called single inheritance.
• Interfaces provide the benefits of multiple inheritance without drawbacks.
• Syntax of a Java class is as follows:
A subclass can modify behavior inherited from a parent class.
• A subclass can create a method with different functionality than the parent’s method but with the same:
• Name
• Return type
• Argument list

Then the new method is said to override the old one.

So, what is the objective of subclass?
The Java programming language semantics dictate that p2.method () results in the child version of the method being executed, because the method is declared private, p2 ( declared as parent ) cannot access it , this the semantics language is violated


3. Invoking Overridden Methods
A subclass method may invoke a superclass method using the
super keyword:
• The keyword super is used in a class to refer to its superclass.
• The keyword super is used to refer to the members of superclass, both data attributes and methods.
• Behavior invoked does not have to be in the superclass; it can be further up in the hierarchy.


المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .