Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Hands-On C++ Practice Notes for Coders part 2

Rating
-
Sold
-
Pages
8
Uploaded on
20-12-2024
Written in
2024/2025

C++ is a general-purpose programming language known for its efficiency, flexibility, and performance. It was developed by Bjarne Stroustrup in 1983 as an extension of the C programming language, introducing object-oriented programming (OOP) features while retaining the power and speed of C.

Show more Read less
Institution
Course

Content preview

Unit IV
1. Inheritance
Inheritance is based on the concept of code reusability. It saves time of program development.
The mechanism of deriving a new derived class (subclass) from an old base class is known as
inheritance.
Types of Inheritance:




2. Defining Derived Classes
■ A derived class can be defined by specifying its relationship with the base class in
addition to its own details.
class derived_class : visibility_mode base_class
{ …………
…………//members of derived class
};
■ Default visibility mode is private
■ Example 1 (Private Derivation):
class ABC : private XYZ
{
members of ABC
};
■ Example 2 (Public Derivation):
class ABC : public XYZ
{
members of ABC
};
■ Example 3 (Default private Derivation):
class ABC : XYZ
{
Page | 1

, members of ABC
};
■ When a base class is privately inherited by a derived class
– Public members of base class become private members of derived class.
– Public members of the base class can only be accessed by member functions of
derived class
■ When a base class is publicly inherited by a derived class
– Public members of base class become public members of derived class.
– They are accessible to the objects of the derived class

3. Single Inheritance
In single inheritance a single sub class is derived from the base class.
Syntax 1:
class A //Base Class
{
……………
A
};
class B: public A //Derived Class
{
………….. B
};
Syntax 2:
class A //Base Class

{
……………
};
class B: private A //Derived Class
{
…………..
};

Example of Single Inheritance:
class base
{ public: int x;
void getdata()
{ cout << "Enter the value of x = ";
cin >> x; }
};
class derive : public base
{
private: int y;
public: void readdata()
{ cout << "Enter the value of y = ";
cin >> y; }
void product()
{ cout << "Product = " << x * y;
} };
void main()
{ derive a;
a.getdata(); a.readdata();
a.product();
}

Page | 2

Written for

Institution
Course

Document information

Uploaded on
December 20, 2024
Number of pages
8
Written in
2024/2025
Type
Class notes
Professor(s)
I don\\\'t know
Contains
All classes

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
myraaa9900

Also available in package deal

Get to know the seller

Seller avatar
myraaa9900 Barkatullah university
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
6
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions