The Artima Developer Community
Sponsored Link

Legacy Design Forum
Designing with Interfaces



This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Interfaces Can Have Same Methods

Posted by Bill Venners on May 25, 2000 at 6:00 AM

> I have a question:

> If you have 2 interfaces below:

> public interface A
> {
> public void sayHello();
> public void sayWorld();
> }

> public interface B
> {
> public void sayHello();
> public void sayYahoo();
> }

> Let a class C implement interfaces A , B:

> public class C implements A,B
> {
> public void sayHello(){ System.out.println("Hello"); //interface does this implementation belongs to ???
> //Will it even compile???

> public void sayWorld(){ System.out.println("World");
> public void sayYahoo(){ System.out.println("Yahoo");
> }

The sayHello() implementation belongs to both interfaces. In
other words, if you cast a reference to a class C object to
either A or B, you can invoke sayHello().



Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us