Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

a problem of multiple inheritance

 
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.
 
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.
 
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.
 
    Bookmark Topic Watch Topic
  • New Topic