Current location - Quotes Website - Signature design - Can a class in Java implement two interfaces with the same method signature? Try to explain it. Thanks
Can a class in Java implement two interfaces with the same method signature? Try to explain it. Thanks

Yes. For example, both interface A and interface B have void a(); this method declaration is not implemented, but the implementation class can only provide one implementation, so it doesn't matter whether it is A or B.

As shown below, this program is correct?public?class?Test?implements?A,B?{ public?static?void?main(String[]?args){?new?Test().a(); } public?void?a()?{ System.out.println("hello"); }?

}

interface?A{ void?a();

}

interface?B{ void?a();

}