Answers for "inheritance op"

11

inheritance

it is used to define relationship between two class, 
which a child class occurs all the properties and behaviours of a parent class. 
Provides code reusability.
Ex: in my framework I have a TestBase class which I store 
all my reusable code and methods. My test execution classes and 
elements classes will extend the TestBase in order to reuse the code.
Posted by: Guest on November-28-2020
0

inheritance

class left {
public:
    void foo();
};

class right {
public:
    void foo();
};

class bottom : public left, public right {
public:
    void foo()
    {
        //base::foo();// ambiguous
        left::foo();
        right::foo();

        // and when foo() is not called for 'this':
        bottom b;
        b.left::foo();  // calls b.foo() from 'left'
        b.right::foo();  // call b.foo() from 'right'
    }
};
Posted by: Guest on October-05-2021
0

inheritance

#include <iostream>

using namespace std;

class Area
{
	public:
		int getArea(int l, int b)
		{
			return l * b;
		}
};

class Perimeter
{
	public:
		int getPerimeter(int l, int b)
		{
			return 2*(l + b);
		}
};

class Rectangle : public Area, public Perimeter
{
	int length;
	int breadth;
	public:
		Rectangle()
		{
			length = 7;
			breadth = 4;
		}
		int area()
		{
			return Area::getArea(length, breadth);
		}
		int perimeter()
		{
			return Perimeter::getPerimeter(length, breadth);
		}
};

int main()
{
	Rectangle rt;
	cout << "Area : " << rt.area() << endl;
	cout << "Perimeter : " << rt.perimeter() << endl;
	return 0;
}
Posted by: Guest on June-18-2021

Browse Popular Code Answers by Language