Write in brief about the creation of base class and derived class

Estudies4you
Q13. Define the following terms,
(i) Base class
(ii) Derived class.
OR
Write in brief about the creation of base class and derived class.
Answer:

(i)  Base Class
Base class is a class from which other classes can be inherited. It is also called as a ‘super class’ or a ‘parent class’. This class does not have any knowledge about its sub-classes. It is constant and cannot be changed. Any number of classes can be derived from a base class.
It is declared or defined before the derived class. The Base class. members can be accessed from the derived class. It is used in creating the classes which reuse the code that is inherited from the base class. There are 2 types of base classes in C++.
They are as follows,
(a) Direct Base Class
(b) Indirect Base Class
Write in brief about the creation of base class and derived class,define base class in c++,define derived class in c++,difference between base and derived class in c++,syntax for base class in c++,syntax for derived class in c++,estudies4you,c++ notes,c++ lecture notes,c++ study material jntuh,oops using c++ notes jntuh

(ii) Derived Class
Derived class is a class that is inherited from a base class. It can inherit all the properties and behavior of the base class. It contains additional members apart from having base class members. It is also called as a ‘subclass’ or a ‘child class’.
It has access to public and protected numbers of base class. It can define its own functions to override the base class function. It can communicate with base class by calling the base class constructor.
Write in brief about the creation of base class and derived class,define base class in c++,define derived class in c++,difference between base and derived class in c++,syntax for base class in c++,syntax for derived class in c++,estudies4you,c++ notes,c++ lecture notes,c++ study material jntuh,oops using c++ notes jntuh

Example
Write in brief about the creation of base class and derived class,define base class in c++,define derived class in c++,difference between base and derived class in c++,syntax for base class in c++,syntax for derived class in c++,estudies4you,c++ notes,c++ lecture notes,c++ study material jntuh,oops using c++ notes jntuh
In the above figure, vehicles is the Base class and the type of vehicles i.e., Car and Bus are derived class members. The derived classes car and Bus inherit the properties of Base class vehicle.

Syntax
class Baseclass
{
-------
};
class Derivedclass: AccessSpecifier Baseclass
{
-------
};


Program
#include<iostream.h>
#include<conio.h>
class Base
{
public:
int a;
};
class Derived : public Base
{
public:
int b;
};
int main()
{
clrscr();
Derived q;
q.a= 10;
q.b = 50;
cout<<“\n Member of Base class is:” <<q.a;
cout<<“\n Member of Derived class is:” <<q.b;
getch();
return 0;
}


Output
Write in brief about the creation of base class and derived class,define base class in c++,define derived class in c++,difference between base and derived class in c++,syntax for base class in c++,syntax for derived class in c++,estudies4you,c++ notes,c++ lecture notes,c++ study material jntuh,oops using c++ notes jntuh

To Top