110 likes | 188 Views
Implementing Inheritance. About OOP Object oriented programming is a tool for new challenges in software development offers a closer fit to the way human think improves communication improves the quality of software. Important OOP concepts:. • Encapsulation • Data hiding
E N D
About OOP Object oriented programming is a tool for new challenges in software development • offers a closer fit to the way human think • improves communication • improves the quality of software
Important OOP concepts: • Encapsulation • Data hiding • Polymorphism • Inheritance
Inheritance It is the capability of one class to inherit properties from other class.
Implementing Inheritance Inheritance is implemented by specifying the name of the base class from which the class being defined (derived class) has to inherit from. Class <class name> : <base class name> { derived class own features }
Different forms of Inheritance Single Inheritance Multiple Inheritance Hierarchical Inheritance Multilevel Inheritance
Single Inheritance Class derived class name : visibility-mode base class name { //members of derived class }
Visibility mode The visibility mode controls the visibility and availability of inherited base members in the derived class. It controls the access specifier to be, for inheritable members of base class, in he derived class.
Relationship of Inheritance and visibility modes Class base Not inheritable Class d2 : private base Class d1 : public base Class z: public d1, private d2
Name the members, which can be accessed from the member functions of class human. • Name the members, which can be accessed by an object of class human. • What will be the size of an object of class human? Class ape{ int organs, bones; public: void readape(); void showape(); }; Class human : public ape { char race[20]; char habitation[25]; public: void readhuman(); void showhuman(); };