Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Samenvatting

Summary C++ INHERITANCE

Beoordeling
-
Verkocht
-
Pagina's
16
Geüpload op
25-07-2024
Geschreven in
2023/2024

The document thoroughly explains inheritance in C++, a key feature of object-oriented programming. It details how classes can inherit properties and methods from base classes, promoting code reuse and hierarchy. Practical examples demonstrate single, multiple, and multilevel inheritance, along with access specifiers (public, protected, private). The notes cover constructors, destructors, and the importance of virtual functions for polymorphism. Emphasizing best practices, the document highlights inheritance's role in creating flexible and maintainable code structures.

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

ELITE TUTORING




C++ Inheritance
Inheritance is one of the key features of Object-oriented programming in C++.
It allows us to create a new class (derived class) from an existing class (base
class).
The derived class inherits the features from the base class and can have
additional features of its own. For example,

class Animal {
// eat() function
// sleep() function
};

class Dog : public Animal {
// bark() function
};


Here, the Dog class is derived from the Animal class. Since Dog is derived
from Animal , members of Animal are accessible to Dog .

,ELITE TUTORING




Inheritance in C++
Notice the use of the keyword public while inheriting Dog from Animal.

class Dog : public Animal {...};


We can also use the keywords private and protected instead of public . We will
learn about the differences between using private , public and protected later in
this topic.




is-a relationship
Inheritance is an is-a relationship. We use inheritance only if an is-a
relationship is present between the two classes.
Here are some examples:

, ELITE TUTORING



• A car is a vehicle.

• Orange is a fruit.

• A surgeon is a doctor.

• A dog is an animal.




Example 1: Simple Example of C++ Inheritance
// C++ program to demonstrate inheritance

#include <iostream>
using namespace std;

// base class
class Animal {

public:
void eat() {
cout << "I can eat!" << endl;
}

void sleep() {
cout << "I can sleep!" << endl;
}
};

// derived class
class Dog : public Animal {

public:
void bark() {
cout << "I can bark! Woof woof!!" << endl;
}
};

int main() {

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
25 juli 2024
Aantal pagina's
16
Geschreven in
2023/2024
Type
SAMENVATTING

Onderwerpen

€5,34
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
peterkuria3

Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
peterkuria3 Harvard University
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
1 jaar
Aantal volgers
1
Documenten
69
Laatst verkocht
-
ELITE TUTORING

Elite Tutoring is your ultimate destination for academic success. I offer a curated selection of high-quality study tools designed to enhance your learning experience and boost exam performance. From comprehensive study guides and interactive practice exams to expert-recommended resources, I provide everything you need to excel. Trust Elite Tutoring to turn your academic challenges into triumphs and help you pass your exams with confidence.

Lees meer Lees minder
0,0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Populaire documenten

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen