+ 2

What is multiple inheritance?

30th Aug 2017, 9:10 AM
Sophia
6 Réponses
+ 2
thanks
30th Aug 2017, 10:41 AM
Sophia
+ 1
If a class inherits from multiple classes
30th Aug 2017, 9:53 AM
Jonas Schröter
Jonas Schröter - avatar
+ 1
in java multiple inheritence is not possible directly..u can achieve that by using interfaces
30th Aug 2017, 2:38 PM
Suhail Pappu
Suhail Pappu - avatar
+ 1
what are interfaces?
31st Aug 2017, 10:52 AM
Sophia
+ 1
For a better understanding, an abstract class is a class which cannot have any instances. An interface is a fully abstract class. If you're implementing an interface, you have to override all methods in there. Like an abstract class, it cannot be instantiated. Often you could use an abstract class instead of an interface, but if you want to use an abstract class, you must inherit from it. Because you can implement as much interfaces as you want, it's better to use them instead of inherit from an abstract class. If you inherit from a class, this class is the superclass of your class which is the subclass. A subclass takes all methods of the superclass and uses them. Then, you can override some methods, for example you want to give your class a specific behaviour. If your superclass is the class names "animals", you could inherit from your brand new class named "elefant". An elefant is an animal, so it eats, sleep and so on. Bit there are differences too, an elefant has a special "voice". If you have a method "speak" you want to override it to give your elefant a voice. That's a good example of abstract methods:You do not know which voice your animal will have when your writing the "animal class", so you make your method abstract. If you aren't looking forwards to write your project with other programmers, you could write the "voice" method anyway without the abstract keyword and override it, but the possibility of bugs is bigger, because you could forget it. That's all an example.😊 You can only inherit from one class while you're able to implement as many interfaces as you want. If that specific interface fits perfectly into your uses, it's better to implement it instead of "wasting" the place for another superclass.
31st Aug 2017, 11:43 AM
Jonas Schröter
Jonas Schröter - avatar
+ 1
Great. Thanks a lot
31st Aug 2017, 1:20 PM
Sophia