• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MultipleImplementation Inheritance using Inner Class

 
Murgan Sub
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • 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 ?
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Multiple Implementation Inheritance.........
- satya
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Syed Jafer
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Maciej Kolodziej
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic