wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes inheriting an innerclass Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inheriting an innerclass" Watch "inheriting an innerclass" New topic
Author

inheriting an innerclass

Peng Fan
Ranch Hand

Joined: May 04, 2004
Posts: 35
please check out the fist block of code

and then the second one

As you can see,the first block of code,the constructor of class IneritInner must receive a ContainInner reference in order to invoke the constructor of class Inner.the reason for doing such is obvious,that is inner class constructor must attach to the enclosing class object.However,in the second block of code InheritInner constructor do not any reference to the class ContainInner.why?
KR Campbell
Ranch Hand

Joined: Mar 26, 2004
Posts: 124
Originally posted by fanny pan:

and then the second one


It is a bit of nest of vipers isn't it? However, if you look closely, you will realise that in the first example InheritInner extends ContainInner.Inner whereas in the second example InheritContainInner extends ContainInner directly. Thus InheritContainInner will directly call the default superclass constructor for you. The first example doesn't actually inherit from ContainInner and needs you to pass in an instance and call its superclass constructor.
Regards,
Ken
Peng Fan
Ranch Hand

Joined: May 04, 2004
Posts: 35
Anybody help me? To be honest, I'm a college student coming from china and currently preparing myself for the SCJP exam, since my college does not provide any java-related course, and i am the only one studying java in my class, and the only material about java i got is Thinking In Java third edition written by Bruce Eckle. So when i get caught in some problems on java(sometimes i feel lost and anonymous), the one that i considered to be my saver is you. hope you to be my learning partner. thank you for your generous supports.
Peng Fan
Ranch Hand

Joined: May 04, 2004
Posts: 35
Are these:
class InheritInner extends ContainInner.Inner{
public InheritInner(ContainInner ci){ci.super();}
}
equivalent to the follow:
class InheritInner extends ContainInner.Inner{
public InheritInner(ContainInner ci){super();ci.super();}
}
Peng Fan
Ranch Hand

Joined: May 04, 2004
Posts: 35
if we have a class C as follow:
class A{
class B{
class C{}
}
}
and make a class named Test to inherit A.B.C, and how can we difine the class Test constructor.THX!
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Is this a academic question?
As far as I know, you use inner classes if you don't want to inherit from them.
Using innerclasses this way will make your projects hard to understand (as you see).


http://home.arcor.de/hirnstrom/bewerbung
KR Campbell
Ranch Hand

Joined: Mar 26, 2004
Posts: 124
Originally posted by fanny pan:
if we have a class C as follow:
class A{
class B{
class C{}
}
}
and make a class named Test to inherit A.B.C, and how can we difine the class Test constructor.THX!

Where *is* this stuff coming from?
As you have probably found, you cannot say

You can say

As Stefan has said this is stepping into the realms of the ridiculous, the whole point of an inner class being that it has an 'intimate' relationship with its superclass. Trying to inherit from an inner class in this way is a bit like trying to sleep with your brother's wife!
Regards,
Ken
KR Campbell
Ranch Hand

Joined: Mar 26, 2004
Posts: 124
Originally posted by fanny pan:
Are these:
class InheritInner extends ContainInner.Inner{
public InheritInner(ContainInner ci){ci.super();}
}
equivalent to the follow:
class InheritInner extends ContainInner.Inner{
public InheritInner(ContainInner ci){super();ci.super();}
}

Time to write some code. A parameterless constructor which you write yourself is essentially the same as a default constructor supplied by the compiler. The difference is that you can add some stuff to find out what is going on. What would happen if you wrote a constructor such as

Why not give it try and experiment?
Regards,
Ken
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: inheriting an innerclass