can you tell me what is the out put
and which interface will call when you want display ()
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
can you tell me what is the out put
and which interface will call when you want display ()
Last edited by helloworld922; April 21st, 2011 at 09:56 AM.
No. Can you tell us? What happened when you wrote a test program to test this?
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Assuming that's all the code, neither. You'll get compile errors.
If you're unsure what code's doing, test it out.
Note that an interface can't be "called", neither can a method in an interface be "called" (since all interface methods are abstract). Only the lowest implementation of that method (with respect to the actual object type) is called.
Also, this is what is referred to as "the diamond problem". (If you have no idea what that is, google it and come back.)
The diamond problem *usually* doesn't happen in Java, because there is no multiple inheritence. However, as you've shown here, you can implement multiple interfaces.
An interface doesn't care how you implement a method, as long as it's there. So it doesn't care if another interface also contains that method definition. It's up to you as a programmer to know what's going on.
Whether or not this is the diamond problem is debatable. Wikipedia says it isn't. But it can be confusing, especially if you want two functions to do completely different things. For example:
public class DiamondProblemTest { public interface Cowboy{ public void draw(); } public interface Artist{ public void draw(); } public static class Person implements Cowboy, Artist{ public void draw(){ //should I pull out a gun or a paintbrush? } } public static void main(String... args){ new Person().draw(); } }
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
The answer's obviously that your person needs to draw pictures with his bullets