It is common to identify situations where an object can have more than one common feature. For example, a beer. Our example may seem unusual, but it will help us for illustration and understanding. Before actually be a beer, it is a drink and can also be a recipe ingredient. Many recipes take beers and that it can also be classified as an ingredient. Analyzing this scenario is that we will explain following the concept of multiple inheritance in object-oriented programming.

Multiple inheritance in OOP

A beer has specific characteristics such as white collar and a yellowish or darker color. It is also a drink which in many cases must be stored in a special way. She is also a type of ingredient, since in cuisine it is very common to use the beer in dishes that take meat and special sauces.

Bringing this scenario for the programming codes, how could a “beer” class have drink attributes and ingredient attributes at the same time? To solve this problem, you must then apply the concept of multiple inheritance. Check out the following example:

class Drink{


public function setType($var)    {

$type = $var;




class Ingredient{



public function setQuantity ($qt)             {

$ qtde = $qt;



public function setRecipeName($name)               {

$ recipename = $name;




class Beer extends Beer, Ingredient{



$beer = new Beer;

$beer. setTypo(“Pilsen”);

$beer. setRecipeName(“Beer Sauce”);

$beer. setQuantity (“2 cups”);


The syntax used to apply the class inheritance is also used to assign one or more classes, separated by commas. The behavior is also the same, from the descendant class it is possible to call the parent class objects. In the example, the beer type is indicated using the setType () method. On the other hand, the amount that will be used in the indicated recipe, is set using the setQuantity () method. Every mentioned method was implemented in a different class.

This dynamism in the use of the concept of heritage optimizes production, ensures the ultimate in code reuse and centralizes the control of the information, as a generic class can be used in several classes descendants.

You might also like…

Scriptcase & Web Services

This time I will explain how to work with web services inside the Scriptcase, directly with PHP and...

More updates in 9.4 version

Recently version 9.4 was released bringing a new design concept to the generated applications of Sc...

Taking a look at version 9.4

Scriptcase released its version 9.4, and this one brings many interesting news, specially regarding...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at Learn more about our Privacy Police.