wood burning stoves*
The moose likes Beginning Java and the fly likes a problem of  multiple inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "a problem of  multiple inheritance" Watch "a problem of  multiple inheritance" New topic
Author

a problem of multiple inheritance

yuqing ma
Greenhorn

Joined: Nov 10, 2004
Posts: 11
interface A{
void printA();
}

interface B{
void pirntB();
void f();
}
class AB implements A,B
{
public void printA(){
System.out.println("Hi,I'm interface A");
}
public void printB(){
System.out.println("Hi,I'm interface B");
}
public static void main(String[] args)
{
AB ab=new AB();
ab.printA();
ab.printB();

}
}
---------- Java Compile ----------
AB.java:9: AB is not abstract and does not override abstract method f() in B
class AB implements A,B
^
1 error

Interfaces provide the flexibility of multiple inheritance without requiring the subclass to implement every method of its superclasses.
why here can't compile.
thankx in advance.
Jeremy Wilson
Ranch Hand

Joined: Feb 18, 2003
Posts: 166
An interface is just a contract a class must follow. class AB does not provide an implementation for void f() in interface B. The interface requirements are not met.


Jeremy Wilson
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Not to contradict the last post, but if you really wanted that f has no implentation in class AB you must declare AB is being abstract.

It has nothing to do with multiple inheritance by the way.

[ November 11, 2004: Message edited by: Barry Gaunt ]
[ November 11, 2004: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
yuqing ma
Greenhorn

Joined: Nov 10, 2004
Posts: 11
what's the meaning as following?
Interfaces provide the flexibility of multiple inheritance without requiring the subclass to implement every method of its superclasses.
yuqing ma
Greenhorn

Joined: Nov 10, 2004
Posts: 11
what's the meaning as following?

Interfaces provide the flexibility of multiple inheritance without requiring the subclass to implement every method of its superclasses.

please give me an example,thanks for all.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a problem of multiple inheritance
 
Similar Threads
Dynamic method lookup
Doubt in multiple inheritance
Redefining a static method in subclass
Abstract and Interface
Same constant names in different Interfaces