Skip to main content

Posts

Showing posts with the label protected methods.

Inherticance in C++

What is inheritance? In object oriented programming, Inheritance is a mechanism by which a new class can be created as an extension of an existing class. Inheritance helps us in code reuse . The existing class is called base class /super class  and new class is called derived class / sub class  or inherited class. Derived class is an extension of base class. It inherits all the members of the base class (even the private members). And it can have new members of its own. Base class members which are public and protected are accessible from derived class object. Private members of base class are not directly accessible in derived class but can be accessed using base class methods. Syntax class derived - class : access - specifier base - class { /* members*/ }; We write derived class name followed by :, followed by public/private/protected followed by base class name. Then the usual definition of class is written where in we write new membe...