'How to implement an override method of implemented interfaces with the same signature in java. And give different implementations for each interface [duplicate]
Let's say I have two interfaces InterfaceA and InterfaceB with the same method signature. InterfaceA:
public interface InterfaceA {
void printInterfaceName();
}
And InterfaceB:
public interface InterfaceB {
void printInterfaceName();
}
And I have a Printing class that is implementing both the interface Printing class:
public class Printing implements InterfaceA, InterfaceB {
// want to override the printInterfaceName() method such way
// so that it will give an output which given in main method comment
}
And I have a Main class with a main method on it
public class Main {
public static void main(String[] args) {
InterfaceA a = new Printing();
InterfaceB b = new Printing();
a.printInterfaceName(); // this is should print `INTERFACE-A`
b.printInterfaceName(); // and this is should print `INTERFACE-B`
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
