Object oriented programming with C++ - Session 5 Inheritance

Describe Single Inheritance Describe Base class and Derived class Access Base class members and use pointers in classes Describe types of inheritance Describe Constructors and Destructors under inheritance Describe how to call Member Functions of the Base Class and Derived Class Describe Container Classes To maintain and reuse class objects easily, we need to be able to relate classes of similar nature to another. Single inheritance is the process of creating new classes from an existing base class. For example let us consider a program in which we are dealing with people employed in an organisation | Inheritance Session 5 Session Objectives Describe Single Inheritance Describe Base class and Derived class Access Base class members and use pointers in classes Describe types of inheritance Describe Constructors and Destructors under inheritance Describe how to call Member Functions of the Base Class and Derived Class Describe Container Classes Object Oriented Programming with C++/ Session 5 / of 41 Single Inheritance To maintain and reuse class objects easily, we need to be able to relate classes of similar nature to another. Single inheritance is the process of creating new classes from an existing base class. For example let us consider a program in which we are dealing with people employed in an organisation. Object Oriented Programming with C++/ Session 5 / of 41 Single Inheritance (Contd.) Each of the subclasses is considered to be derived from the class Employee. The class Employee is called the base class and the newly created class is called the derived class. . | Inheritance Session 5 Session Objectives Describe Single Inheritance Describe Base class and Derived class Access Base class members and use pointers in classes Describe types of inheritance Describe Constructors and Destructors under inheritance Describe how to call Member Functions of the Base Class and Derived Class Describe Container Classes Object Oriented Programming with C++/ Session 5 / of 41 Single Inheritance To maintain and reuse class objects easily, we need to be able to relate classes of similar nature to another. Single inheritance is the process of creating new classes from an existing base class. For example let us consider a program in which we are dealing with people employed in an organisation. Object Oriented Programming with C++/ Session 5 / of 41 Single Inheritance (Contd.) Each of the subclasses is considered to be derived from the class Employee. The class Employee is called the base class and the newly created class is called the derived class. Employee Director Manager Secretary Clerk Object Oriented Programming with C++/ Session 5 / of 41 Single Inheritance (Contd.) In a class hierarchy, the derived classes inherit the methods and variables of the base class. They can also have properties and methods of their own. Class: Manager m_name, m_age, m_Emp_id, m_salary m_department perks, no_of_employees reporting Class: Employee Name, Age, Emp_id Salary, Department Object Oriented Programming with C++/ Session 5 / of 41 Advantages Most important advantage: reusability of code. Once a base class has been created it can be adapted to work in different situations. Result of reusability of code is the development of class libraries. A class library consists of data and methods encapsulated in a class. Deriving a class from an existing one allows redefining a member function of the base class and also adding new members to the derived class. The base class remains unchanged in the process. Object Oriented Programming with C++/ .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.