The document discusses public, protected, and private inheritance in C++. It explains that private inheritance makes all base class members private in the derived class, protected inheritance makes base class protected members protected and public members public, and public inheritance makes protected members protected and public members public. It provides examples of each type of inheritance and how base and derived class constructors and destructors work.
Object oriented programming with pythonArslan Arshad
A short intro to how Object Oriented Paradigm work in Python Programming language. This presentation created for beginner like bachelor student of Computer Science.
Object oriented programming with pythonArslan Arshad
A short intro to how Object Oriented Paradigm work in Python Programming language. This presentation created for beginner like bachelor student of Computer Science.
Strategies for Effective Upskilling is a presentation by Chinwendu Peace in a Your Skill Boost Masterclass organisation by the Excellence Foundation for South Sudan on 08th and 09th June 2024 from 1 PM to 3 PM on each day.
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...NelTorrente
In this research, it concludes that while the readiness of teachers in Caloocan City to implement the MATATAG Curriculum is generally positive, targeted efforts in professional development, resource distribution, support networks, and comprehensive preparation can address the existing gaps and ensure successful curriculum implementation.
This presentation was provided by Steph Pollock of The American Psychological Association’s Journals Program, and Damita Snow, of The American Society of Civil Engineers (ASCE), for the initial session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session One: 'Setting Expectations: a DEIA Primer,' was held June 6, 2024.
How to Add Chatter in the odoo 17 ERP ModuleCeline George
In Odoo, the chatter is like a chat tool that helps you work together on records. You can leave notes and track things, making it easier to talk with your team and partners. Inside chatter, all communication history, activity, and changes will be displayed.
Normal Labour/ Stages of Labour/ Mechanism of LabourWasim Ak
Normal labor is also termed spontaneous labor, defined as the natural physiological process through which the fetus, placenta, and membranes are expelled from the uterus through the birth canal at term (37 to 42 weeks
Thinking of getting a dog? Be aware that breeds like Pit Bulls, Rottweilers, and German Shepherds can be loyal and dangerous. Proper training and socialization are crucial to preventing aggressive behaviors. Ensure safety by understanding their needs and always supervising interactions. Stay safe, and enjoy your furry friends!
Safalta Digital marketing institute in Noida, provide complete applications that encompass a huge range of virtual advertising and marketing additives, which includes search engine optimization, virtual communication advertising, pay-per-click on marketing, content material advertising, internet analytics, and greater. These university courses are designed for students who possess a comprehensive understanding of virtual marketing strategies and attributes.Safalta Digital Marketing Institute in Noida is a first choice for young individuals or students who are looking to start their careers in the field of digital advertising. The institute gives specialized courses designed and certification.
for beginners, providing thorough training in areas such as SEO, digital communication marketing, and PPC training in Noida. After finishing the program, students receive the certifications recognised by top different universitie, setting a strong foundation for a successful career in digital marketing.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
2. Inheritance -
Introduction
• Definition :Deriving methods and Data from an
existing class to a new class .
• Use : we don’t need to redefine them in the
new class. (Reusability) Class A {
• Inheritance access control: Data Members ;
Member Functions
– Private }
– Protected Class B : public A
{
– Public Data Members;
Member Functions
}
3. B D
Three Types of Access Control
Suppose B is a super class and D is derived from B then
If private inheritance, then all the members of B which are
protected or public will be private in D.
If protected inheritance, then all the members of B which
are protected or public will be protected in D.
If public inheritance, then all the members of B which are
protected will also be protected in D and all the members of
B which are public will also be public in D.
4. Private Inheritance
Class B
protected: int x
public: void f1()
Class D: private B
private: int y
public: void f2()
• int x and void f1() will be private in Class D.
If a member is private in what places it can be accessed?
Same Class and friends of the Class
5. Protected Inheritance
Class B
protected: int x
public: void f1()
Class D: protected B
private: int y
public: void f2()
• int x and void f1() will be protected in Class D.
If a member is Protected in what places it can be accessed?
Same Class and friends of the Class,derived class and its friends
6. Public Inheritance
Class B
protected: int x
public: void f1()
Class D: public B
private: int y
public: void f2()
• int x will be protected in Class D.
• void f1() will be public in Class D.
• What about Private data members ?
7. Sample Program
#include <iostream.h>
class Patient { void InPatient::InSetdetails (int Wnum, int
public: Dys)
void Setdetails(int, char); { Wardnum = Wnum;
void Displaydetails(); Daysinward = Dys;
private: }
int IdNumber; char Name; };
void Patient::Setdetails (int Idnum, char void InPatient :: InDisplaydetails ()
Namein) { cout << endl << "Ward Number is "
{ IdNumber = Idnum; Name = << Wardnumber;
Namein; } cout << endl << "Number of days in
void Patient::Displaydetails() ward "
{ cout << endl << IdNumber << Name; } << Daysinward;
}
class InPatient : public Patient void main()
{ public: { InPatient p1;
void InSetdetails (int, int); p1.Setdetails(1234, 'B');
void InDisplaydetails(); p1.Displaydetails();
p1.InSetdetails(3,14);
private:
p1.InDisplaydetails();
int Wardnum, Daysinward; }; }
8. Sample Program from Lecture 18:
Change public to protected inheritance
#include <iostream.h> private:
class Patient { int Wardnum, Daysinward; };
public:
void Setdetails(int, char); void InPatient::InSetdetails (int Wnum, int
void Displaydetails(); Dys)
private: { Wardnum = Wnum;
int IdNumber; char Name; }; Daysinward = Dys;
void Patient::Setdetails (int Idnum, char }
Namein) void InPatient :: InDisplaydetails ()
{ IdNumber = Idnum; Name = Namein; } { cout << endl << "Ward Number is "
void Patient::Displaydetails() << Wardnumber;
{ cout << endl << IdNumber << Name; } cout << endl << "Number of days in
ward "
class InPatient : protected Patient { << Daysinward;
public: }
void InSetdetails (int, int); void main()
void InDisplaydetails(); { InPatient p1;
p1.Patset();
void Patset() { Setdetails(4321, ‘X’); } p1.PatDisp();
void PatDisp() { Displaydetails(); } p1.InSetdetails(3,14);
p1.InDisplaydetails(); }
9. Sample Program from Lecture 18:
Change public to private inheritance
#include <iostream.h> void InPatient::InSetdetails (int Wnum, int Dys)
class Patient { { Wardnum = Wnum;
public: Daysinward = Dys;
void Setdetails(int, char); }
void Displaydetails();
private: void InPatient :: InDisplaydetails ()
int IdNumber; char Name; }; { cout << endl << "Ward Number is "
void Patient::Setdetails (int Idnum, char << Wardnumber;
Namein) cout << endl << "Number of days in ward "
{ IdNumber = Idnum; Name = Namein; } << Daysinward;
void Patient::Displaydetails() }
{ cout << endl << IdNumber << Name; } void main()
{ InPatient p1;
class InPatient : private Patient { p1.Patset();
public: p1.InSetdetails(3,14);
void InSetdetails (int, int); p1.InDisplaydetails();
void InDisplaydetails(); }
void Patset() { Setdetails(4321, ‘X’); }
private:
We can access Setdetails() inside
int Wardnum, Daysinward; }; Inpatient though it is private to
Inpatient but public to Patient.
10. Base-class and Derived-class
Constructor and Destructor
• When an object of derived class is created the base class
constructor is called first and then the derived class
constructor is called.
Example // Program1
• If the derived-class constructor is omitted, the derived class’s
default constructor ( which is System Generated ) calls the
base-class’s default constructor Program 2
• Destructors are called in the reverse order of constructor
calls, so a derived-class destructor is called before its base-
class destructor.
11. Person
Student Lecturer
int main() Person’s object is created
{ Person Pers1; Person’s object is created
Student Stud1; Student’s object is created
Lecturer Lec1; Person’s object is created
} Lecturer’s object is created
12. Base-class Initialiser: Sample Program 1 -
Explicit Constructor definition
#include <iostream.h> void main() {
class Base { Base b1;
protected: int x, y; b1.set();
public:
Base () {cout<<"Constructing Base Derived d1;
object"<<endl;} d1.set();
~Base() {cout<<"Destructing Base }
object"<<endl;}
void set() { x = 10; y = 20; Output:
cout<<x<<y<<endl;}
}; Constructing Base object
class Derived : public Base { 10 20
private: int a, b;
public: Constructing Base object
Derived() {cout<<"Constructing Derived Constructing Derived object
object"<<endl;} 40 60
~Derived() {cout<<"Destructing Derived
object"<<endl;} Destructing Derived object
void set() { a = 40; b = 60; Destructing Base object
cout<<a<<b<<endl; } Destructing Base object
};
13. Base-class Initialiser: Sample Program 1
(No user-defined constructor for
derived class)
#include <iostream.h> void main() {
class Base { Base b1;
protected: int x, y; b1.set();
public:
Base () {cout<<"Constructing Base Derived d1;
object"<<endl;} d1.set();
~Base() {cout<<"Destructing Base }
object"<<endl;}
void set() { x = 10; y = 20; Output:
cout<<x<<y<<endl;}
}; Constructing Base object
class Derived : public Base { 10 20
private: int a, b;
public: Constructing Base object
void set() { a = 40; b = 60; 40 60
cout<<a<<b<<endl; }
}; Destructing Base object
Destructing Base object
14. Base-class Initialiser
• A base-class initialiser can be provided in the derived-class
constructor to call the base-class constructor explicitly;
• otherwise, the derived class’s constructor will call the base
class’s default constructor implicitly.
15. Base-class Initialiser: Sample
Program 2
#include <iostream.h> class Circle: public Point {
class Point { public:
public: Circle(double, int, int); //constructor
~Circle(); //destructor
Point (int, int); //constructor private:
~Point(); //destructor double radius;
protected: };
int x, y;
Circle::Circle(double r, int a, int b) : Point(a,b)
};
{ radius = r;
Point::Point(int a, int b) cout<<"Circle constructor: radius is
{ x = a; y = b; "<<radius<<'['<<x<<", "<<y<<']'<<endl;
cout<<"Point constructor: "<<'['<<x<<", }
"<<y<<']';
cout<<endl; } Circle::~Circle()
{ cout<<"Circle destructor: radius is
"<<radius<<'['<<x<<", "<<y<<']'<<endl;
Point::~Point() }
{ cout<<"Point destructor: "<<'['<<x<<",
"<<y<<']'; cout<<endl; }
16. Base-class Initialiser: Sample
Program 2 (cont.)
int main() Output:
{ {
Point p(11, 22); Point constructor: [11, 22]
Point destructor: [11, 22]
}
cout<<endl; Point constructor: [72, 29]
Circle circle1(4.5, 72, 29); Circle constructor: radius is 4.5 [72, 29]
cout<<endl;
Point constructor: [5, 5]
Circle circle2(10, 5, 5);
Circle constructor: radius is 10 [5, 5]
cout<<endl;
return 0; Circle destructor: radius is 10 [5, 5]
} Point destructor: [5, 5]
Circle destructor: radius is 4.5 [72, 29]
Point destructor: [72, 29]