SlideShare una empresa de Scribd logo
1 de 35
Descargar para leer sin conexión
Kinan keshkeh 
IT Engineering-Damascus University 
3rd year 
Summer course- 2014 
2 bytes team
• 
Who has any Ques? 
• 
So Let’s Go ! 
• 
What we will take : 
• 
See a program for example. 
• 
Inheritance concept 
• 
Some NOTES !!
Inheritance !
Inheritance !
Inheritance 
•is the process by which a new class—known as a derived class—is created from another class, called the base class
Inheritance 
•is the process by which a new class—known as a derived class—is created from another class, called the base class 
•A derived class automatically has all the member variables and all the ordinary member functions that the base class has, and can have additional member functions and additional member variables.
Inheritance 
•We have Parent class “ Vehicle” and child class “ Wheeled vehicle” and child of child “Car” . 
•So each “Car” is a “ Wheeled vehicle” and “Vehicle” .
Inheritance 
•To derive class from base class , we write : class DerivedClass : public BaseClass{ class_members }
Inheritance 
•To derive class from base class , we write : class DerivedClass : public BaseClass{ class_members } 
• A class that is a parent of a parent of a parent of another class, is often called an ancestor class 
• If class A is an ancestor of class B, then class B is often called a descendant of class A
Inheritance 
•The members of the Child classes are members from the Parent classes , so any operation or any function is defined in Parent class , will be defined in Child classes .
Inheritance 
•The members of the Child classes are members from the Parent classes , so any operation or any function is defined in Parent class , will be defined in Child classes . 
•The other way isn’t correct !!
Inheritance 
•Base Class Employee :
Inheritance 
•Base Class Employee :
Inheritance
Inheritance 
•Derived Class HourlyEmployee :
Inheritance 
•Derived Class SalariedEmployee:
Inheritance 
•.cpp HourlyEmployee:
Inheritance
Inheritance 
•.cpp SalariedEmployee :
Inheritance
Inheritance 
//This is the application file employee_test.cpp. 
#include <iostream> 
#include "hourlyemployee.h" 
#include "salariedemployee.h" 
using namespace std; 
using namespace SavitchEmployees; 
void showEmployeeData(const Employee object); 
int main( ) 
{ 
HourlyEmployee joe("Mighty Joe","123-45-6789", 20.50, 40); 
SalariedEmployee boss("Mr. Big Shot","987-65-4321", 10500.50); 
showEmployeeData(joe); 
showEmployeeData(boss); 
return 0; 
} 
void showEmployeeData(const Employee object) 
{ 
cout << "Name: " << object.getName( ) << endl; 
cout << "Social Security Number: " 
<< object.getSsn( ) << endl; 
} 
•.cpp Main :
Inheritance 
•If a function is defined in Parentclass and in Childclass , Then an Object from Child can reach to the function In Parentclass By this method : 
•ChildClass Object. ParentClass :: function(parameters)
Inheritance 
•CONSTRUCTORS IN DERIVED CLASSES : 
•A constructor in a base class is not inherited in the derived class, but you can invoke a constructor of the base class within the definition of a derived class constructor .
Inheritance 
•CONSTRUCTORS IN DERIVED CLASSES : 
•A constructor in a base class is not inherited in the derived class, but you can invoke a constructor of the base class within the definition of a derived class constructor . 
• constructors are called in hierarchial , from BaseClass constructors  CalledClass constructors .
Inheritance 
•CONSTRUCTORS IN DERIVED CLASSES : 
Derived::Derived(const Derived& Object) 
: Base(Object), <probably more initializations> 
{ 
... 
}
Inheritance 
•DESTRUCTOR IN DERIVED CLASSES : 
•The Destructor for the ParentClass is called automatically from the ChildClass Destructor , so just define the ChildClasses Destructors .
Inheritance 
•DESTRUCTOR IN DERIVED CLASSES : 
•The Destructor for the ParentClass are called automatically from the ChildClass Destructor , so just define the ChildClasses Destructors . 
•The Destruction is in an opposite way of the Construction!!
Inheritance 
•you cannot access a private member variable or private member function in the definition or implementation of a derived class. 
•THE protected QUALIFIER :
Inheritance 
•you cannot access a private member variable or private member function in the definition or implementation of a derived class. 
•THE protected QUALIFIER : 
•if a member is marked as protected in a base class, then it can be accessed by name in the definitions of all descendant classes, not just in those classes directly from the base class.
Inheritance 
•THE protected QUALIFIER :
Inheritance 
•NOTES : 
•Overloaded assignment operators and constructors are not inherited. 
•You have to Overload it using the operator in ParentClass like that: 
Derived& Derived::operator =(const Derived& rightSide) 
{ 
Base::operator =(rightSide); 
... 
}
Inheritance 
•NOTES : 
•It’s not necessary for ChildClass and ParentClass being from the same Namespace !
Inheritance 
•NOTES : 
•It’s not necessary for ChildClass and ParentClass being from the same Namespace ! 
•You can inherit from more one class ! 
childClass: ParentClass1, ParentClass2 {… …. }
That’s for today 
Go and Play !! 
That’s for today guys !! 
Bye Bye !
2 bytes team 
Group : group link Mobile phone- Kinan : 0994385748 Facebook account : kinan’s account 
2 bytes team

Más contenido relacionado

Similar a 2 BytesC++ course_2014_c11_ inheritance

full defination of final opp.pptx
full defination of final opp.pptxfull defination of final opp.pptx
full defination of final opp.pptxrayanbabur
 
SystemVerilog_Classes.pdf
SystemVerilog_Classes.pdfSystemVerilog_Classes.pdf
SystemVerilog_Classes.pdfssusere9cd04
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented ProgrammingRatnaJava
 
Object oriented programming new syllabus presentation
Object oriented programming new syllabus presentationObject oriented programming new syllabus presentation
Object oriented programming new syllabus presentationiqraamjad1405
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingNithyaN19
 
Unit 7 inheritance
Unit 7 inheritanceUnit 7 inheritance
Unit 7 inheritanceatcnerd
 
Super Keyword in Java.pptx
Super Keyword in Java.pptxSuper Keyword in Java.pptx
Super Keyword in Java.pptxKrutikaWankhade1
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++VishnuSupa
 
Pi j3.1 inheritance
Pi j3.1 inheritancePi j3.1 inheritance
Pi j3.1 inheritancemcollison
 

Similar a 2 BytesC++ course_2014_c11_ inheritance (20)

29csharp
29csharp29csharp
29csharp
 
29c
29c29c
29c
 
INHERITANCE.pptx
INHERITANCE.pptxINHERITANCE.pptx
INHERITANCE.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
full defination of final opp.pptx
full defination of final opp.pptxfull defination of final opp.pptx
full defination of final opp.pptx
 
SystemVerilog_Classes.pdf
SystemVerilog_Classes.pdfSystemVerilog_Classes.pdf
SystemVerilog_Classes.pdf
 
OOP
OOPOOP
OOP
 
Lecturespecial
LecturespecialLecturespecial
Lecturespecial
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Java(inheritance)
Java(inheritance)Java(inheritance)
Java(inheritance)
 
Object oriented programming new syllabus presentation
Object oriented programming new syllabus presentationObject oriented programming new syllabus presentation
Object oriented programming new syllabus presentation
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
 
Unit 7 inheritance
Unit 7 inheritanceUnit 7 inheritance
Unit 7 inheritance
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
 
Inheritance
Inheritance Inheritance
Inheritance
 
session 24_Inheritance.ppt
session 24_Inheritance.pptsession 24_Inheritance.ppt
session 24_Inheritance.ppt
 
Super Keyword in Java.pptx
Super Keyword in Java.pptxSuper Keyword in Java.pptx
Super Keyword in Java.pptx
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Pi j3.1 inheritance
Pi j3.1 inheritancePi j3.1 inheritance
Pi j3.1 inheritance
 

Más de kinan keshkeh

10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)kinan keshkeh
 
Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm kinan keshkeh
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...kinan keshkeh
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graphkinan keshkeh
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_unitskinan keshkeh
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_listskinan keshkeh
 
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked listkinan keshkeh
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointerskinan keshkeh
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfileskinan keshkeh
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfileskinan keshkeh
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_recordskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templateskinan keshkeh
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphismkinan keshkeh
 

Más de kinan keshkeh (20)

10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)
 
Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists
 
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism
 

Último

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durbanmasabamasaba
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 

Último (20)

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 

2 BytesC++ course_2014_c11_ inheritance

  • 1. Kinan keshkeh IT Engineering-Damascus University 3rd year Summer course- 2014 2 bytes team
  • 2. • Who has any Ques? • So Let’s Go ! • What we will take : • See a program for example. • Inheritance concept • Some NOTES !!
  • 5. Inheritance •is the process by which a new class—known as a derived class—is created from another class, called the base class
  • 6. Inheritance •is the process by which a new class—known as a derived class—is created from another class, called the base class •A derived class automatically has all the member variables and all the ordinary member functions that the base class has, and can have additional member functions and additional member variables.
  • 7. Inheritance •We have Parent class “ Vehicle” and child class “ Wheeled vehicle” and child of child “Car” . •So each “Car” is a “ Wheeled vehicle” and “Vehicle” .
  • 8. Inheritance •To derive class from base class , we write : class DerivedClass : public BaseClass{ class_members }
  • 9. Inheritance •To derive class from base class , we write : class DerivedClass : public BaseClass{ class_members } • A class that is a parent of a parent of a parent of another class, is often called an ancestor class • If class A is an ancestor of class B, then class B is often called a descendant of class A
  • 10. Inheritance •The members of the Child classes are members from the Parent classes , so any operation or any function is defined in Parent class , will be defined in Child classes .
  • 11. Inheritance •The members of the Child classes are members from the Parent classes , so any operation or any function is defined in Parent class , will be defined in Child classes . •The other way isn’t correct !!
  • 15. Inheritance •Derived Class HourlyEmployee :
  • 16. Inheritance •Derived Class SalariedEmployee:
  • 21. Inheritance //This is the application file employee_test.cpp. #include <iostream> #include "hourlyemployee.h" #include "salariedemployee.h" using namespace std; using namespace SavitchEmployees; void showEmployeeData(const Employee object); int main( ) { HourlyEmployee joe("Mighty Joe","123-45-6789", 20.50, 40); SalariedEmployee boss("Mr. Big Shot","987-65-4321", 10500.50); showEmployeeData(joe); showEmployeeData(boss); return 0; } void showEmployeeData(const Employee object) { cout << "Name: " << object.getName( ) << endl; cout << "Social Security Number: " << object.getSsn( ) << endl; } •.cpp Main :
  • 22. Inheritance •If a function is defined in Parentclass and in Childclass , Then an Object from Child can reach to the function In Parentclass By this method : •ChildClass Object. ParentClass :: function(parameters)
  • 23. Inheritance •CONSTRUCTORS IN DERIVED CLASSES : •A constructor in a base class is not inherited in the derived class, but you can invoke a constructor of the base class within the definition of a derived class constructor .
  • 24. Inheritance •CONSTRUCTORS IN DERIVED CLASSES : •A constructor in a base class is not inherited in the derived class, but you can invoke a constructor of the base class within the definition of a derived class constructor . • constructors are called in hierarchial , from BaseClass constructors  CalledClass constructors .
  • 25. Inheritance •CONSTRUCTORS IN DERIVED CLASSES : Derived::Derived(const Derived& Object) : Base(Object), <probably more initializations> { ... }
  • 26. Inheritance •DESTRUCTOR IN DERIVED CLASSES : •The Destructor for the ParentClass is called automatically from the ChildClass Destructor , so just define the ChildClasses Destructors .
  • 27. Inheritance •DESTRUCTOR IN DERIVED CLASSES : •The Destructor for the ParentClass are called automatically from the ChildClass Destructor , so just define the ChildClasses Destructors . •The Destruction is in an opposite way of the Construction!!
  • 28. Inheritance •you cannot access a private member variable or private member function in the definition or implementation of a derived class. •THE protected QUALIFIER :
  • 29. Inheritance •you cannot access a private member variable or private member function in the definition or implementation of a derived class. •THE protected QUALIFIER : •if a member is marked as protected in a base class, then it can be accessed by name in the definitions of all descendant classes, not just in those classes directly from the base class.
  • 31. Inheritance •NOTES : •Overloaded assignment operators and constructors are not inherited. •You have to Overload it using the operator in ParentClass like that: Derived& Derived::operator =(const Derived& rightSide) { Base::operator =(rightSide); ... }
  • 32. Inheritance •NOTES : •It’s not necessary for ChildClass and ParentClass being from the same Namespace !
  • 33. Inheritance •NOTES : •It’s not necessary for ChildClass and ParentClass being from the same Namespace ! •You can inherit from more one class ! childClass: ParentClass1, ParentClass2 {… …. }
  • 34. That’s for today Go and Play !! That’s for today guys !! Bye Bye !
  • 35. 2 bytes team Group : group link Mobile phone- Kinan : 0994385748 Facebook account : kinan’s account 2 bytes team