The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include <conio.h>
class A
{
public:
int a, b, c;
virtual void test() = 0;
A(int a, int b)
{
cout << "Hello I am the constructor" << endl;
}
};
class B : public A
{
int y;
public:
B(int i, int j) : A(a, b)
{
a = i;
b = j;
c = a + b;
}
void test() { cout << "The sum is = " << c << endl; }
};
void main()
{
clrscr();
B obj(4, 5);
obj.test();
getch();
}
//.......Coded by RISHAB NAIR
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
class A
{
public:
int a, b, c;
virtual void test() = 0;
A(int a, int b)
{
cout << "Hello I am the constructor" << endl;
}
};
class B : public A
{
int y;
public:
B(int i, int j) : A(a, b)
{
a = i;
b = j;
c = a + b;
}
void test() { cout << "The sum is = " << c << endl; }
};
int main(void)
{
B obj(4, 5);
obj.test();
return 0;
}
//.......Coded by RISHAB NAIR
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP