Can we Achieve multiple inheritance using interface??If it's yes give one example else give reason? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can we Achieve multiple inheritance using interface??If it's yes give one example else give reason?

21st Jan 2020, 5:33 AM
Punith M S
Punith M S - avatar
5 Answers
+ 6
In java you can not inherit more than one class because it's make harder to maintain the codes.But java provides interface , actually it limited to 65,535 due to jvm limitations.You can not implement more than 65,535 interfaces.Find more about interfaces here https://www.sololearn.com/discuss/1923650/?ref=app https://www.sololearn.com/discuss/43857/?ref=app https://www.sololearn.com/discuss/148094/?ref=app https://www.sololearn.com/discuss/837263/?ref=app https://www.sololearn.com/discuss/1645457/?ref=app https://www.sololearn.com/discuss/1669267/?ref=app
21st Jan 2020, 2:21 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 4
Interfaces can also have a default method which contains the implementation. This is similar to an abstract class having a concrete method. That way you can actually do multiple inheritance via interfaces (this is also called "Mixin"). Here is a detail example http://hannesdorfmann.com/android/java-mixins
21st Jan 2020, 6:13 AM
Tibor Santa
Tibor Santa - avatar
21st Jan 2020, 8:09 AM
Avinesh
Avinesh - avatar
+ 1
with interfaces you can achieve sort of multiple. implementing an interface doesn't give the 'child'-class the method it just forces it to have that method hope this helps you 😁
21st Jan 2020, 5:47 AM
Anton Böhler
Anton Böhler - avatar
+ 1
multiple inheritance is possible if there is not conflict with same method name (or if you reimplement conflict method) interface A { default String m(){return "A";} } interface B { default String m(){return "B";} } public class Prg implements A,B { //error public static void main(String[] args) { var p = new Prg(); System.out.println( p.m() ); } }
21st Jan 2020, 10:22 AM
zemiak