programplug Logo




C++ Inheritance


Object Oriented Programming provide a feature of inheritance.Inheritance is a process to create new class which acquires the properties of existing class with some changes.


class new_class_name: public old_class_name
{
statement 1
statement 2
statement 3
}

C++ Inheritance Example

#include   
class School
{  
   public:int id=2; 
};  
   class Student: public School
   {  
   public:int roll_no=1;    
   };       
void main() 
{  
  Student s;  
  cout << "Id: " << s.id << endl;    
  cout << "Roll No: "<< s.roll_no << endl;     
}   

output:
Id: 2
Roll No: 1


Multilevel Inheritance

When one class inherits another class which is again inherited by another class,is known as multilevel inheritance in C++.

#include 
class A
{  
   public:void aa() 
   {   
	cout << "Hello..."<< endl;   
   }    
};  
class B: public A   
{    
   public:void bb()
   {  
    cout <<" How Are You..."<< endl;   
   }    
};   
class C: public B   
{    
	public:void cc() 
	{  
	 cout <<" Where Are You From...";   
	}    
};   
void main() 
{  
  C c;  
  c.aa();  
  c.bb();  
  c.cc();   
}  

output:
Hello...
How Are You...
Where Are You From...







Our Services

Developing Cheapest Websites
Offer Digital Marketing
Provide College Projects
Attractive Website Developing
Summer Training,Industrial Training
SCO,SMO

Contact Us

Dehradun Uttarakhand India
www.programplug.com
info@programplug.com
08534019974
Designed By : Mridul Gupta

Other Link

About Us

Contact Us

Disclaimer

Privacy Policy