Copy link to clipboard
Copied
Hi there guys,
Can I implement more than one interface to the same class?
One option is to make interface A extend interface B and than have my class inplementing interface A. Is there any other way that I can implement two or more interfaces directly to the same class?
Thank you!
You can implement multiple interfaces just by separating them with a comma:
public class ClassName implements interface1, interface2
Copy link to clipboard
Copied
You can implement multiple interfaces just by separating them with a comma:
public class ClassName implements interface1, interface2
Copy link to clipboard
Copied
I tried that and gave me an error, that's why I ended up here.
Probably I spelled something wrong.
Thanks mate!
Copy link to clipboard
Copied
Maybe - because you can definitely do it. One thing to be aware of though is when you're typing your object - if you use the base class that implements the interfaces you can call methods from either interface. But if you type your object to one of the interfaces you can only call methods defined by that interface...