110 likes | 192 Views
Object-oriented programming (OOP) is a powerful tool that offers a closer fit to human thinking, improves communication, and enhances software quality. Key OOP concepts include Encapsulation, Data Hiding, Polymorphism, and Inheritance. Inheritance allows a class to inherit properties from another class. Implementing Inheritance involves specifying the base class from which the derived class inherits. Different forms of Inheritance include Single, Multiple, Hierarchical, and Multilevel. Visibility modes control the access specifier for inherited base members in the derived class. Learn about the relationship of Inheritance and visibility modes. Explore which members can be accessed from member functions and objects of a class. Understand object size in OOP through examples in classes like "ape" and "human."
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(); };