wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes MultipleImplementation Inheritance using Inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "MultipleImplementation Inheritance using Inner Class" Watch "MultipleImplementation Inheritance using Inner Class" New topic
Author

MultipleImplementation Inheritance using Inner Class

Murgan Sub
Greenhorn

Joined: Feb 06, 2002
Posts: 22
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

Joined: Jun 03, 2000
Posts: 5040
Multiple Implementation Inheritance.........
- satya


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
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 ]

SCJP2. Please Indent your code using UBB Code
Syed Jafer
Greenhorn

Joined: Jan 30, 2002
Posts: 3
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

Joined: Aug 26, 2001
Posts: 7610
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 ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Maciej Kolodziej
Greenhorn

Joined: Feb 11, 2002
Posts: 26
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).


MK
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

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

Joined: Jul 03, 2001
Posts: 2120
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MultipleImplementation Inheritance using Inner Class