Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a problem of multiple inheritance

 
yuqing ma
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
yuqing ma
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic