Skip to main content

Multiple Inheritance

Multiple Inheritance

In multiple inheritance a class can access the property of more than one class. This inheritance is use for multiple accessing of properties. In multiple inheritance ambiguty is 

occured when same name function is declare in both class and the object is confuse with function is called. 
syntax −

class derived-class: access baseA, access baseB....
Where access is one of public, protected, or private and would be given for every base class and they will be separated by comma as shown above. Let us try the following 

example −

#include <iostream.h>
#include <conio.h> 
// Base Class
class Shape 
{
   public:
      void getwidth(int w) {
         width = w;
      }
      void getheight(int h) {
         height = h;
      }
      
   protected:
      int width;
      int height;
};

// Base class Cost
class cost 
{
   public:
      int getCost(int area) {
         return area * 120;
      }
};

// Derived class
class Rectangle: public Shape, public Cost 
{
   public:
      int getArea() 
     {
         int a=width * height;
             return a;
      }
};

void main() 
{
   Rectangle Rect;
   int area;
    
   Rect.getwidth(5);
   Rect.getheight(7);

   area = Rect.getArea();
   

   cout << "Total area: " << Rect.getArea() << endl;

   cout << "Total cost: Rs." << Rect.getCost(area) << endl;

   getch();
}

Run it

Comments

Popular posts from this blog

Learn Programming in UNIX

Q: - Write a program to input two numbers and add them?             gedit add.sh             clear             echo “enter two numbers:”             read a             read b             sum=`expr$a+$b`             echo $sum Syntax for if-else:- (1)          if test condition             then                 ---------                 --...

Things you know before buying Laptop

Things you should know before purchasing Laptop 1. Brand of Company Like DELL (inspiron Only), HP, ACER 2. Required RAM capacity Like 4 GB aprox. 3. Requirement of Hard Disk like 500 GB or 1 TB. 4. Processor like Intel Core i3 or Dual Core or AMD processor 5. Multimedia keyboard 6. Optical Mouse 7. ATI graphics Card Note:- If you think to buy a laptop you can select the laptop without operating system or open source operating system because if you buy windows o/s for laptop then it increased price aproxx 3000 if you select DOS laptop then its reduced the windows cost. Click here for example --> Best Laptop for students

CODD RULES of RDBMS

Codd’s rules for RDBMS (i)                 The information rule. (ii)              Guaranteed access of   data (iii)            Systematic treatment of null value. (iv)            On line DB support. (v)              Comprehensive sup-language rule. (vi)            The view update rule. (vii)         Insert update rule. (viii)       Physical data independence. (ix)            Logical data independence. (x)              Integrity rule (xi)  ...