Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of...
-
Upload
priscilla-williams -
Category
Documents
-
view
224 -
download
0
Transcript of Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of...
![Page 1: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/1.jpg)
![Page 2: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/2.jpg)
Need for Inheritance
Capability of inheriting features.
Transitive relationship.
Reusablity of class.
![Page 3: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/3.jpg)
Presented By
Lakshmi Kumari
K.V. Shaktinagar
![Page 4: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/4.jpg)
Content
• Introduction
• Different forms of inheritance
• Visibility mode
• Accessibility of base class member
• Assignment
![Page 5: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/5.jpg)
INHERITANCE
The mechanism of deriving a new class from an old one is called Inheritance.
![Page 6: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/6.jpg)
Raj
Father
Rani Roshan
Base Class
Derived Class
Existing class is called Base Class.
New class is called derived class.
![Page 7: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/7.jpg)
INHERITANCE
SINGLE INHERITANCE MULTIPLE INHERITANCE
MULTILEVELINHERITANCE
HIERARCHICALINHERITANCE
HYBRID INHERITANCE
![Page 8: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/8.jpg)
When a subclass inherit only from one base class,it is known as single inheritance.
Super Class
Derived Class
Super Class(Base Class)
Sub Class(Derived Class)
![Page 9: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/9.jpg)
Syntax:
Class Derived-class : Mode base-class
{
St1;
St2;
};
Colon gives that derived class-name is derived from base-class.
Mode is either private or public.By default mode is private
![Page 10: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/10.jpg)
Base Class & Derived Class
The new class is called Derived Class and old one is called Base class.
Class Student{ Public: int Roll;};
Class Ipstudent : public Student{ Private : int ipmarks; Public : void info( )
{ cout<< Roll; cout<<ipmarks; }
}; Main( )
{ ipstudent ip;
ip.Roll=1;
Ip.info( );
}
![Page 11: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/11.jpg)
When many subclasses inherit from a single base class ,it is known as hierarchical inheritance.
![Page 12: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/12.jpg)
Syntax:
Class Derived-class : Mode base-class1,Mode base-class2
{
St1;
St2;
};Mode is either private or public.By default mode is private
Name of different base class
![Page 13: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/13.jpg)
Super Class
Sub Class 2
Sub Class 1
When a subclass inherits from a class that itself inherits from another class it is known as multilevel inheritance.Slide 6
![Page 14: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/14.jpg)
When one subclass inheriting from many base class ,it is known as hierarchical inheritance.Syntax:
![Page 15: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/15.jpg)
When a subclass inherits from multiple base classes and all of its base classes inherit from a single base class,this form of inheritance is known as hybrid inheritance..
![Page 16: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/16.jpg)
Visibility Mode
• Private When base class is privately accessed by derived class then
• Public member Private
• Protected member Private
• Private member Not inherited
Base Class Derived Class
become
![Page 17: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/17.jpg)
Visibility Mode
• Public When base class is publicly accessed by derived class then
• Private member Not inherited
• Public member Public
• Protected member Protected
Base Class Derived Class
![Page 18: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/18.jpg)
Visibility Mode
• Protected When base class is accessed protectly by derived class then
• Private member Not inherited
• Public member Protected
• Protected member Protected
Base Class Derived Class
![Page 19: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/19.jpg)
The significance of visibility modes
• Private :-When the derived class require to use some attributes of the base class and these inherited features are intended not to be inherited further .
• Public :-When the situation wants the derived class to have all the attributes of the base class,plus some extra attributes.
• Protected:- When the features are required to be hidden from the outside world and at same time required to be inheritable.
![Page 20: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/20.jpg)
Accessibility of base class memberAccess Specifier Accessible from
own class Accessible from derived class(inheritable)
Accessible from object outside class
Public Yes Yes Yes
Protected Yes Yes No
Private Yes No No
![Page 21: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/21.jpg)
Assignment
• What is inheritance?
• How many type of inheritance?
• When should one derive a class publicly or privately?
![Page 22: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/22.jpg)
class PUBLISHER{
char Pub[12];double Turnover;
protected:void Register();
public:PUBLISHER();void Enter();void Display();
}; class BRANCH{
char CITY[20];protected:
float Employees;public:
BRANCH();void Haveit();void Giveit();
}; class AUTHOR:private BRANCH,public PUBLISHER{
int Acode; char Aname[20];
float Amount;public:
AUTHOR();void Start();void Show();
};
1.Write the names of data members, which are accessible from objects belonging to class AUTHOR.2.Write the names of all the member functions which are accessible from objects belonging to class BRANCH.3. Write the names of all the members which are accessible from member functions of class AUTHOR.4 How many bytes will be required by an object belonging to class AUTHOR?
![Page 23: Need for Inheritance Capability of inheriting features. Transitive relationship. Reusablity of class.](https://reader036.fdocuments.in/reader036/viewer/2022062515/56649d0b5503460f949ded18/html5/thumbnails/23.jpg)
May you all prosper and be happy! With a lot of love and respect
Thank You all