Inheritance allows one class to inherit properties and behaviors from another parent class. This creates a hierarchical relationship between classes and allows code reuse. There are three types of access specifiers that determine whether inherited members from the parent class are public, private, or protected in the child class. Virtual functions allow runtime polymorphism by overriding functions in derived classes. Pure virtual functions define an interface for derived classes by requiring them to implement the function.
Inheritance, pointers, virtual functions, and polymorphism are essential concepts in object-oriented programming. Here's a brief explanation of each:
Inheritance:
Inheritance is a mechanism in object-oriented programming that allows a new class (a derived or child class) to inherit properties and behaviors from an existing class (a base or parent class).
It promotes code reuse and hierarchy in class relationships.
The derived class can extend or override the inherited attributes and methods, making it more specialized while retaining the common characteristics from the base class.
Pointers:
Pointers are variables that store memory addresses, allowing you to work with memory and objects more efficiently.
In object-oriented programming, pointers are often used to reference objects, enabling dynamic allocation of objects and polymorphism.
Pointers are critical for dynamic memory management and creating data structures like linked lists and trees.
Virtual Functions:
Virtual functions are functions defined in a base class and marked with the virtual keyword.
They enable late binding or runtime polymorphism, allowing derived classes to provide their own implementation of the virtual function.
Virtual functions are crucial for achieving polymorphism and are used in conjunction with pointers to objects.
Polymorphism:
Polymorphism is the ability of objects of different classes to respond to the same method or function call in a way that is specific to their individual types.
There are two types of polymorphism: compile-time polymorphism (function overloading) and runtime polymorphism (achieved through virtual functions).
Polymorphism simplifies code and enables you to work with objects at a higher level of abstraction, using a common interface.
In summary, inheritance allows classes to inherit properties and behaviors from other classes, pointers are used to reference objects and manage memory, virtual functions enable runtime polymorphism, and polymorphism allows objects of different types to be treated as instances of a common base class. These concepts are fundamental to designing flexible and extensible object-oriented software.
Inheritance, pointers, virtual functions, and polymorphism are essential concepts in object-oriented programming. Here's a brief explanation of each:
Inheritance:
Inheritance is a mechanism in object-oriented programming that allows a new class (a derived or child class) to inherit properties and behaviors from an existing class (a base or parent class).
It promotes code reuse and hierarchy in class relationships.
The derived class can extend or override the inherited attributes and methods, making it more specialized while retaining the common characteristics from the base class.
Pointers:
Pointers are variables that store memory addresses, allowing you to work with memory and objects more efficiently.
In object-oriented programming, pointers are often used to reference objects, enabling dynamic allocation of objects and polymorphism.
Pointers are critical for dynamic memory management and creating data structures like linked lists and trees.
Virtual Functions:
Virtual functions are functions defined in a base class and marked with the virtual keyword.
They enable late binding or runtime polymorphism, allowing derived classes to provide their own implementation of the virtual function.
Virtual functions are crucial for achieving polymorphism and are used in conjunction with pointers to objects.
Polymorphism:
Polymorphism is the ability of objects of different classes to respond to the same method or function call in a way that is specific to their individual types.
There are two types of polymorphism: compile-time polymorphism (function overloading) and runtime polymorphism (achieved through virtual functions).
Polymorphism simplifies code and enables you to work with objects at a higher level of abstraction, using a common interface.
In summary, inheritance allows classes to inherit properties and behaviors from other classes, pointers are used to reference objects and manage memory, virtual functions enable runtime polymorphism, and polymorphism allows objects of different types to be treated as instances of a common base class. These concepts are fundamental to designing flexible and extensible object-oriented software.
The genetic characters transmitted from parent to offspring, taken collectively.
Something, as a quality, characteristic, or other immaterial possession, received from progenitors or predecessors as if by succession.
↓↓↓↓ Read More:
@ Kindly Follow my Instagram Page to discuss about your mental health problems-
-----> https://instagram.com/mentality_streak?utm_medium=copy_link
@ Appreciate my work:
-----> behance.net/burhanahmed1
Thank-you !
oops(object oriented programing ) is introduced in c++ to enhance the 'c' programming. oops concept includes many important concepts like class,objects,abstraction,encapsulation,inheritance etc.
The genetic characters transmitted from parent to offspring, taken collectively.
Something, as a quality, characteristic, or other immaterial possession, received from progenitors or predecessors as if by succession.
↓↓↓↓ Read More:
@ Kindly Follow my Instagram Page to discuss about your mental health problems-
-----> https://instagram.com/mentality_streak?utm_medium=copy_link
@ Appreciate my work:
-----> behance.net/burhanahmed1
Thank-you !
oops(object oriented programing ) is introduced in c++ to enhance the 'c' programming. oops concept includes many important concepts like class,objects,abstraction,encapsulation,inheritance etc.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
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.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
2. Inheritance
• Inheritance: The mechanism by which one class can inherit the
properties of another.
• Inheritance: A parent-child relationship between classes
• Inheritance allows sharing of the behavior of the parent class into its
child classes.
• child class can add new behavior or override existing behavior from parent
• It allows a hierarchy of classes to be built, moving from the most
general to the most specific.
• Eg: point -> 3D_point -> sphere…
3. Base Class, Derived Class
• Base Class
• Terms to describe the parent in the relationship, which shares its functionality
• Also called Superclass, Parent class
• Derived Class
• Terms to describe the child in the relationship, which accepts functionality
from its parent
• Also called Subclass, Child class
• General Syntax:
• class derivedClassName : AccessSpecifier
baseClassName{… … …}
4. Example: Base Class
class base
{
int x;
public:
void setx(int n)
{ x = n; }
void showx()
{ cout << x << ‘n’ }
};
5. Example: Derived Class
// Inherit as public
class derived : public base {
int y;
public:
void sety(int n)
{ y = n; }
void showy()
{ cout << y << ‘n’;}
};
6. Access Specifier: public
• The keyword public tells the compiler that base will be
inherited such that:
• all public members of the base class will also be public members
of derived.
• However, all private elements of base will remain private to
it and are not directly accessible by derived.
8. An Incorrect Example
class derived : public base {
int y;
public:
void sety(int n) { y = n; }
/* Error ! Cannot access x, which is
private member of base. */
void show_sum() {cout << x+y; }
};
9. Access Specifier: private
• If the access specifier is private:
• public members of base become private members of
derived.
• these members are still accessible by member functions
of derived.
10. Example: Derived Class
// Inherit as private
class derived : private base {
int y;
public:
void sety(int n) { y = n; }
void showy() { cout << y << ‘n’;}
};
11. Example: main()
int main() {
derived ob;
ob.setx(10); // Error! setx() is private.
ob.sety(20); // OK!
ob.showx(); // Error! showx() is private.
ob.showy(); // OK!
}
12. Example: Derived Class
class derived : private base {
int y;
public:
// setx is accessible from within derived
void setxy(int n, int m) { setx(n); y = m; }
// showx is also accessible
void showxy() { showx(); cout<<y<< ‘n’;}
};
13. Protected Members
• Sometimes you want to do the following:
• keep a member of a base class private
• allow a derived class access to it
• Use protected members!
• If no derived class, protected members is the same as private
members.
14. Protected Members
The full general form of a class declaration:
class class-name {
// private members
protected:
// protected members
public:
// public members
};
15. 3 Types of Access Specifiers
• Type 1: Inherit as Private
Base Derived
Private members Inaccessible
Protected members Private members
Public members Private members
16. 3 Types of Access Specifiers
• Type 2: Inherit as Protected
Base Derived
Private members Inaccessible
Protected members Protected members
Public members Protected members
17. 3 Types of Access Specifiers
• Type 3: Inherit as Public
Base Derived
Private members Inaccessible
Protected members Protected members
Public members Public members
18. Constructor and Destructor
• It is possible for both the base class and the derived class to have
constructor and/or destructor functions.
• The constructor functions are executed in order of derivation.
• i.e. the base class constructor is executed first.
• The destructor functions are executed in reverse order.
19. Passing arguments
• What if the constructor functions of both the base class and
derived class take arguments?
1. Pass all necessary arguments to the derived class’s constructor.
2. Then pass the appropriate arguments along to the base class.
20. Example: Constructor of base
class base {
int i;
public:
base(int n) {
cout << “constructing base n”;
i = n; }
~base() { cout << “destructing base n”; }
};
21. Example: Constructor of derived
class derived : public base {
int j;
public:
derived (int n, int m) : base (m) {
cout << “constructing derivedn”;
j = n; }
~derived() { cout << “destructing derivedn”;}
};
22. Example: main()
int main() {
derived o(10,20);
return 0;
}
OUTPUT:
constructing base
constructing derived
destructing derived
destructing base
24. base 1 base 2
derived
Multiple Inheritance
• Type 2:
25. Example: Type 2 (first base class)
// Create first base class
class B1 {
int a;
public:
B1(int x) { a = x; }
int geta() { return a; }
};
26. Example: Type 2 (second base class)
// Create second base class
class B2 {
int b;
public:
B2(int x) { b = x; }
int getb() { return b; }
};
27. Example: Type 2 (inherit two base classes)
// Directly inherit two base classes.
class D : public B1, public B2 {
int c;
public:
D(int x, int y, int z) : B1(z), B2(y) {
c = x; }
void show() {
cout << geta() << getb() << c;}
} ;
28. Potential Problem
• Base is inherited twice by Derived 3!
Derived 3
Base Base
Derived 1 Derived 2
29. Virtual Base Class
• To resolve this problem, virtual base class can be used.
class base {
public:
int i;
};
30. Virtual Base Class
// Inherit base as virtual
class D1 : virtual public base {
public:
int j;
};
class D2 : virtual public base {
public:
int k;
};
31. Virtual Base Class
/* Here, D3 inherits both D1 and D2.
However, only one copy of base is present */
class D3 : public D1, public D2 {
public:
int product () { return i * j * k; }
};
32. Pointers to Derived Classes
• A pointer declared as a pointer to base class can also be used to point
to any class derived from that base.
• However, only those members of the derived object that were
inherited from the base can be accessed.
33. Example
base *p; // base class pointer
base B_obj;
derived D_obj;
p = &B_obj; // p can point to base object
p = &D_obj; // p can also point to derived object
34. Virtual Function
• A virtual function is a member function
• declared within a base class
• redefined by a derived class (i.e. overriding)
• It can be used to support run-time polymorphism.
36. Example
class derived : public base {
public:
derived (int x) : base (x) {}
// The keyword virtual is not needed.
void func() {cout << i * i; }
};
37. Example
int main() {
base ob(10), *p;
derived d_ob(10);
p = &ob;
p->func(); // use base’s func()
p = &d_ob;
p->func(); // use derived’s func()
}
38. Pure Virtual Functions
• A pure virtual function has no definition relative to the base class.
• Only the function’s prototype is included.
• General form:
virtual type func-name(paremeter-list) = 0
39. Example: area
class area {
public:
double dim1, dim2;
area(double x, double y)
{dim1 = x; dim2 = y;}
// pure virtual function
virtual double getarea() = 0;
};