• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MultipleImplementation Inheritance using Inner Class

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at this code below..
class A {}
abstract class B {}
class Z extends A {
B makeB() { return new B() {}; }
}
public class MultiImplement {
static void takesA(A a) {}
static void takesB(B b) {}
public static void main(String[] args) {
Z z = new Z();
takesA(z);
takesB(z.makeB());
}
}

With concrete or abstract classes, inner
classes are the only way to produce the effect
of "multiple implementation inheritance ?
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Multiple Implementation Inheritance.........
- satya
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surely he is meaning two improperly mixed things:
a)multiple inheritance. In Java only via inner classes
b)multiple implementation of interfaces.
[ February 12, 2002: Message edited by: Jose Botella ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a doubt here. If a class is declared abstract, then it must have atleast one abstract methods. Right? But in the code I don't see any abstract methods.
Correct me if I am wrong.
Thanks in advance
Jafer
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope, an class can be declared abstract without containing an abstract method (see *Adapter classes in java.awt.event). But if it contains one or more abstract methods then it MUST be declared abstract.
HIH
[ February 12, 2002: Message edited by: Valentin Crettaz ]
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jose Botella:
Surely he is meaning two improperly mixed things:
a)multiple inheritance. In Java only via inner classes
b)multiple implementation of interfaces.
[ February 12, 2002: Message edited by: Jose Botella ]


NO, I think he means what he writes:
Multiple implementation inheritance means inheritance from more than one non-interface (implementation).
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

NO, I think he means what he writes:
Multiple implementation inheritance means inheritance from more than one non-interface

Okay, so where is inheritance from more than one non-interface in this example....

A inherits from Object
B inherits from Object
Z inherits from A
MultiImplement inherits from Object.
Am I missing something............
- satya
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Madhav
Z "multiple inherits" from A and B
This a sort of multiple inheritance:
takesB(z.makeB());
whenever an object of type Z needs to be seen as an object of type B, the method shown produces an object of type B that has access to all the state and behaviour of the object. (Because it is an inner class)
 
reply
    Bookmark Topic Watch Topic
  • New Topic