Ad Code

CS - 304 Double Quiz || Cs - 304 Quiz no 2 || cs 304 2020 || Vicky Lab



. What is an Object? 

An object is, 

1. Something tangible (Ali, School, House, Car). 2. Something conceptual (that can be apprehended intellectually for example time, date and so on…). 

An object has, 

1. State (attributes)

2. Well-defined behavior (operations)

3. Unique identity

Advantage of Multiple Inheritance: 

As was the case with simple (single) inheritance multiple inheritance also decreases redundant code as we can inherit a class from many classes and can use their functions without the need to write them again.

However, there are more disadvantages of multiple inheritance, than its advantages. 

Problems with Multiple Inheritance 

Increased complexity 

Amphibious vehicle hierarchy is a complicated as this class is derived from two classes that will make code more complex and less understandable however this is obvious as amphibious vehicle is a complicated vehicle. It is generic problem. 

Reduced understanding 

Due to increased complexity of class hierarchy the object model becomes difficult it understand especially for someone who is looking it first time. 

Duplicate features 

As we are deriving a single class from more than one class so there is a chance of duplication of features (same methods in both parents), following problems may arise due to duplicate features, 

Problem 1: Ambiguity   Consider the class hierarchy of Mermaid class below,

 


As mermaid also needs to eat and its both parents have their own methods of eating so here question arises,

Which eat operation Mermaid should inherit as both functions are available? 

Solution – We can solve this problem by explicitly calling eat method from any of the parent classes in Mermaid class according to behaviour of Mermaid (i.e. if it eats like a Woman we can call eat method of Woman class and if eats like Fish we can call method of Fish class), for this we will Override the Common method in multiply inherited class and in that class overridden method we will call the appropriate base class function.   



Post a Comment

0 Comments

Close Menu