Answer Posted / sabari
Deriving only one class from base class is called single inheritance.
For example:
#include<iostream.h>
#include<conio.h>
class student
{
public:
int rno;
char na[30];
void input();
};
void student::input()
{
cout<<"enter the student name";
cin>>na;
cout<<"enter the register no:";
cin>>rno;
}
class mark:public student //derivation
{
int m1,m2,m3;
float t,av;
public:
void display()
{
cout<<"Enter m1,m2,m3 values\n"
cin>>m1>>m2>>m3;
t=m1+m2+m3;
av=t/3;
cout<<endl<<"name="<<na;
cout<<endl<<"Register number="<<rno;
cout<<endl<<"total="<<t;
cout<<endl<<"average="<<av;
}
};
void main()
{
clrscr();
mark ob;
ob.input();
ob.display();
getch();
}
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
What is for loop and its syntax?
Is html an oop?
How do you achieve polymorphism?
which feature are not hold visual basic of oop?
What is class and object with example?
Why is there no multiple inheritance?
Give an example where we have to specifically use C programming language and C++ programming language cannot be used?
What is polymorphism oop?
what is different between oops and c++
Why do we need polymorphism in c#?
when to use 'mutable' keyword and when to use 'const cast' in c++
write string class as your own class in java without using any built-in function
c++ program to swap the objects of two different classes
What does sksksk mean in text slang?
How do you use inheritance in unity?