Can a Class implement two interfaces with the same method signature
I created two interfaces with same method signature.
You can actually implement the method only once.
package com.anjana;
public interface Interface2 {
public String printme();
}
package com.anjana;
public interface Interface1 {
public String printme();
}
package com.anjana;
public class Employee implements Interface1,Interface2,Interface3{
@Override
public String printme() {
return "Hello";
}
public static void main(String args[]){
Interface1 emp1=new Employee();
emp1.printme();
System.out.println(emp1.printme());
Interface2 emp2=new Employee();
System.out.println(emp2.printme());
}
You can actually implement the method only once.
package com.anjana;
public interface Interface2 {
public String printme();
}
package com.anjana;
public interface Interface1 {
public String printme();
}
package com.anjana;
public class Employee implements Interface1,Interface2,Interface3{
@Override
public String printme() {
return "Hello";
}
public static void main(String args[]){
Interface1 emp1=new Employee();
emp1.printme();
System.out.println(emp1.printme());
Interface2 emp2=new Employee();
System.out.println(emp2.printme());
}
This will be misleading if you have to do some operations based on the returned value.
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon. Core spun Melange
ReplyDelete