ADVANCE PROGRAMMING
GROUP PROJECT
PROGRAMMING
INHERITANCE
PREPARED FOR :
DR. NOR HASBIAH BINTI UBAIDULLAH
PREPARED BY: MARAN CHANTHIRAN M20121000841 MUSTAKIM BIN BAHARUDIN M20121000839 SHARIMAN HAFIZAN BIN SHAMSUDIN M20112001355
Tugasan 1
Sebagai seorang guru yang mengajar pengaturcaraan berorientasi objek, anda perlu menerangkan salah satu konsep penting dalam OOP iaitu pewarisan kepada pelajar dalam kelas anda. Penerangan anda perlu jelas agar ia mudah difahami oleh pelajar. Sehubungan itu anda dikehendaki menyertakan contoh pewarisan yang bersesuaian dalam penerangan anda dan sertakan gambarajah sekiranya ia membantu penerangan anda. Seterusnya terangkan apakah kebaikan pewarisan dalam pengkodan aturcara kepada pelajar anda.
INHERITANCE
1.0 INTRODUCTION
Inheritance is a relation given to the classes in a program. A class can acquire the other class members. Inherited members are available for a class's use as though they were defined in the same class. Inheritance occurs when one class is derived from another. The strength of inheritance is to reuse the existing class and modify the existing class to a new class. Reusing the existing code minimizes the re-occurrences of instructions in a program. This unit introduces you to the inheritance feature of OOP.
Inheritance is the capability by which the objects of one class inherit the members of the objects in another class.
Consider class1 and class2. Class1 is used to derive/create class2. Class1 is called the base class and class2 is called the derived class.
To understand inheritance, consider the following example.
Figure 1:Example for Inheritance
In the Figure 1, the class Automobile can be classified into
Car class Bus class
In the example, Automobile is the base class. Car and Bus are called derived classes and belong to the base class Automobile. They share common characteristics and functions. For