answersLogoWhite

0

  • Computers
  • Computer Programming
  • Java Programming
  • C++ Programming

When will you use multiple inheritance and when will you use multi level inheritance?

User Avatar

Wiki User

βˆ™ 2007-01-11 06:51:12

Best Answer
Copy

Multiple inheritance is used when a new class to be formed has to inherit characteristics from two or more classes. eg: class scientist class labourer | | | | V V -------------------------------- | class employee | -------------------------------- Multilevel inheritance is used if a derived class inherits characteristics from a base class which is a derived class (intermmediate base class). If the inheritance level is more than two then it is a multilevel inheritance. eg: class Grandfather | | V class Father | | V class son

2007-01-11 06:51:12
This answer is:
πŸ€“
🀯
πŸ€”
User Avatar

Add your answer:

Earn +5 pts
Q: When will you use multiple inheritance and when will you use multi level inheritance?
Write your answer...
Submit

Related Questions

When will you use multiple inheritance and when will you use multi level inheritance Describe with an example?

* When asked in an interview or otherwise a brief answer is: "Multiple Inheritance is when a derived class inherits properties and methods from multiple classes as opposed to Single Inheritance. So, for cases where I find that I have two or more classes and another new class is to be created that has properties and behaviour of both or all the base classes then I use Multiple inheritance. For example, If base class one is Terrestrial and Base Class two is Aquatic, then the new class Amphibian will be case of multiple inheritance deriving from both the two base classes."


How many levels of inheritance can be possible with multi level inheritance?

There is no limit actually. But, it is preferable to keep the levels under 6-7 for ease of use and maintenance


What is the differences between Java and C plus plus inheritance?

in java inheritance does not support multiple inheritance therefore we use interface.where as in c plus plus supprot the multiple inheritance.


How can you use multiple inheritance in c plus plus and not in java?

Yes, you are right, you can use multiple inheritance in c plus plus and not in Java. What is the question?


Why is multiple inheritance not possible in C?

C is not object-oriented -- you can't even use single inheritance let alone multiple inheritance.


What is single inheritance and multi inheritance?

1. Single InheritanceA Scenario where one class is inheriting/extending the behavior of just one super class.Ex: public class Ferrari extends Car {…}This can be taken much further, where one class is inheriting/extending the bahavior of another class which in turn is inheriting behavior from yet another class.Ex: public class Automobile {…}Public class Car extends Automobile {…}Public class Ferrari extends Car {…}This multi-level inheritance actually has no limitations on the number of levels it can go. So as far as Java goes, it is limitless. But for maintenance and ease of use sakes it is better to keep the inheritance levels to a single digit number.2. Multiple InheritanceThis type of inheritance allows for a class to inherit from more than one superclass. That is, a child class can have more than one parent.Ex.public class ArmoredCar extends Car, TankAs with single inheritance, there can be many levels of multiple inheritance.Unfortunately, multiple inheritance is much more complicated to properly implement than single inheritance, due to what is known as namespace collision. For instance, what if both the Car and the Tank classes above have a method Drive(). Which superclass method does ArmoredCar use, if it doesn't explicitly specify its own Drive() method? If it wants to extend one, how does it do that? In the context of the ArmoredCar class, what does the super() method refer to? Languages which attempt to allow multiple inheritance run into a large number of these problems, which require either compiler or language workarounds, making them both more verbose and more complex than languages which allow only single inheritance.Do note that languages which support multiple inheritance do not require its use - programs in such languages can solely use single inheritance. In general, most OO languages suggest using multiple inheritance where very substantial savings in code and/or design logic can be realized over a single inheritance design.Java does not support Multiple Inheritance. C++ is a common language which does allow Multiple Inheritance.


Dicuss the different types of inheritance?

Types of InheritanceThere exists basically three types of inheritanceMultilevel inheritanceMultiple inheritanceHierarchical inheritanceIn single inheritance, one class extends one class only. In multilevel inheritance, the ladder of single inheritance increases. In multiple inheritance, one class directly extends more than one class and in hierarchical inheritance one class is extended by more than one class. Let us go in detail programmatically.1. Multilevel InheritanceIn multilevel, one-to-one ladder increases. Multiple classes are involved in inheritance, but one class extends only one. The lowermost subclass can make use of all its super classes' members. Multilevel inheritance is an indirect way of implementing multiple inheritance. Following program explains.2. Multiple InheritanceIn multiple inheritance, one class extends multiple classes. Java does not support multiple inheritance but C++ supports. The above program can be modified to illustrate multiple inheritance. The following program does not work.3. Hierarchical InheritanceIn hierarchical type of inheritance, one class is extended by many subclasses. It is one-to-many relationship. A realtime example is available at dynamic binding.Biswajit Das,


Can you use multiple inheritance in .NET?

Multiple inheritance in C# In C#, the classes are only allowed to inherit from a single parent class, which is called single inheritance. But you can use interfaces or a combination of one class and interface(s), where interface(s) should be followed by class name in the signature.


How multiple inheritance is done in java?

Java doesn't have multiple inheritance proper. It is possible for a class to implement different interfaces - however, in this case, only the method names are "inherited", not their contents. It is also possible to use composition instead of inheritance: an object can contain objects of different classes, and use the methods of the objects it contains - but this, too, is a different mechanism than inheritance.


Why do object-oriented programmers oppose using multiple inheritence?

Not all of them do; C++ uses multiple inheritance.The designers of Java decided to do away with several aspects of C++ that may cause confusion, this includes multiple inheritance, pointers, and several other aspects.The possible confusion with multiple inheritance arises when both parents have a method or field with the same name. Which one to use in the child?To have some of the benefits of multiple inheritance, Java supports interfaces instead. A class can implement multiple interfaces.


Why is multiple inheritance implemened through interfaces?

Interfaces have only methods declared and not defined. So that these various methods can be altered or customized or written according to the need. Hence Multiple inheritance is implemented through Interfaces.Interface is a progam which just declares various methods or functions, so that any user can write the contents of that method declaration.AnswerTrue Multiple Inheritance refers to the ability to inherit from multiple CLASSES. Thus, a true multiple inheritance language does not use interfaces. However, many single-inheritance languages provide most of the benefits of the multiple inheritance concept by using interfaces (Java, for example). The problem with true Multiple Inheritance is twofold:(a) at the compiler and runtime level, it is often difficult to determine which method is being referred to, as M.I. can lead to very convoluted (and sometimes conflicting) namespaces(b) there is no specific superclass, which can lead to problems with determining relationships between classesUsing a S.I. model with interfaces avoids these two problems.


What is the difference between the c plus plus and java?

C plus supports the use of pointers, where as java does not. because the use of pointers may makes the coding difficult. C plus supports multiple inheritance. where as java does not supports multiple inheritance. java is platform independent.


What is the Definition of multiple inheritance?

Direct Multiple Inheritance in Object Oriented terms is the feature where one class extends/inherits the features of multiple classes. ex: Assuming there is a class A which has method a() and class B which has method b() - Now if we need a class C that needs the features of both A and B it could be like: public class C extends A, B { ... } This way it can use both the methods a() and b(). Unfortunately Java does not support direct multiple inheritance. You can achieve partial multiple inheritance using interfaces.


What are the advantages of a multi-size memory card reader?

A multi size memory card reader will allow you to use multiple memory cards on one single reader, instead of buying multiple readers.


What is the use of interface in java other than multiple inheritance?

doba jeva tari jode ans magyo to


Need of interface in java?

Interfaces are used in Java to accomplish most of the goals of Multiple Inheritance. For several reasons, Java only supports Single Inheritance for classes - i.e. a class can have only a single parent. The use of Interfaces is how Java attempts to implement most of the positives of the concept of Multiple Inheritance while avoiding its pitfalls.


What is the Difference between multiple inheritance and multilevel inheritance in java?

Multilevel InheritanceA Scenario where one class is inheriting/extending the bahavior of another class which in turn is inheriting behavior from yet another class.Ex: public class Automobile {…}Public class Car extends Automobile {…}Public class Ferrari extends Car {…}This multilevel inheritance actually has no limitations on the number of levels it can go. So as far as java goes, it is limitless. But for maintenance and ease of use sakes it is better to keep the inheritance levels to a single digit number.Multiple InheritanceActually, java does not support multiple inheritance. You can achieve partial multiple inheritance using interfaces but java is not like C or C++ where you can do direct multiple inheritance. However, you can achieve partial multiple inheritance with the help of interfaces.Ex: public class FerrariF12011 extends Ferrari implements Car, Automobile {…}And this is under the assumption that Car and Automobile are interfaces.Here if you see, though you don't inherit concrete code from the Car or the Automobile interface, you do inherit skeleton methods that determine the way your class eventually behaves and hence this can be considered partial Multiple Inheritance.


Can interface extends another interface?

yes of cause interface is use in java at the place of multiple inheritance .o as like multiple inheritance u can extends interface class to other. and another think is interface contain abstract method i.e method with no defination so u can use it without any error.


What are the types of inheritance in c plus plus?

There are essentially just two types of inheritance: single inheritance and multiple inheritance. Single inheritance simply means that one class derives directly from another class. Multiple inheritance means one class is directly derived from two or more classes. However, since base classes can (and often are) be derived from other base classes, you can think of this type of inheritance as being multi-level. In addition, two or more base classes that share a common base class can use virtual inheritance. What this means is that the common base class becomes a direct base class of the most-derived class, and this one instance is shared, virtually, by all the base classes that would otherwise inherit directly from it. in other words, there is only one instance of the common base class, rather than one instance per class that inherits from it. This is useful in the so-called "dreaded diamond" formation, where a derived class inherits from two base classes, both of which inherit from a common base class.


Which type of inheritance does not support by java?

Multiple inheritance:The concept of Getting the properties from multiple class objects to sub class object with same priorities is known as multiple inheritance.Java Doesn't Support multiple Inheritance.Diamond problem: In multiple inheritance there is every chance of multiple properties of multiple objects with the same name available to the sub class object with same priorities leads for the ambiguity.We have two classes B and c which are inheriting A class properties.Here Class D inheriting B class and C class So properties present in those classes will be available in java.But both classes are in same level with same priority.If we want to use show() method that leads to ambiguityThis is called diamond problem.Because of multiple inheritance there is chance of the root object getting created more than once.Always the root object i.e object of object class hast to be created only once.Because of above mentioned reasons multiple inheritance would not be supported by java.Thus in java a class can not extend more than one class simultaneously. At most a class can extend only one class.Inheritance means getting the properties from one class object to another class object.Means if any class extending another class then the super class methods can be used in sub classes happily.But in interfaces the methods in interfaces are fully abstract so we need to provide functionlity in our extended class and use it .seems both are opposite right? yes.That is the reason we can say interfaces are only supports syntactical multiple inheritance which is not implementation of multiple inheritance.source: instanceofjavaforus.blogspot.in/2014/12/why-java-does-not-supports-multiple.html


How do you achieve multiple inheritence using class in java?

Multiple Inheritance cannot be achieved only by using Classes in Java. You would have to use Interfaces as well to achieve multiple Inheritance. Java as such does not support direct multiple inheritance. We can have theoretical multiple inheritance by using interfaces using which you can outline the kind of functionality your child classes can have. For example you can have a declaration like this public class A implements X, Y, Z { } Here this class A would have to implement the methods that are declared in the interfaces X, Y & Z. So the outline of the functionality that A would have can be found by checking the interfaces but the exact implementation would depend on the programmer who codes class 'A'


Hierarchical inheritance program in java?

Hierarchical Inheritance is also known as Multi-Level Inheritance.Multilevel InheritanceA Scenario where one class is inheriting/extending the bahavior of another class which in turn is inheriting behavior from yet another class.Ex: public class Automobile {…}Public class Car extends Automobile {…}Public class Ferrari extends Car {…}This multilevel inheritance actually has no limitations on the number of levels it can go. So as far as java goes, it is limitless. But for maintenance and ease of use sakes it is better to keep the inheritance levels to a single digit number.


What is a use inheritance?

Code Re-use is one of the biggest uses of Inheritance


When more than one document program is open at the same time?

It is called multi-tasking or multiple use.


Is unix is multiprogramming OS?

Yes, although to use multi-programming effectively your hardware needs to have multiple CPUs.