Forums Register Login

inheriting an innerclass

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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();}
}
+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
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).
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
 

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
You get good luck from rubbing the belly of a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 826 times.
Similar Threads
Questions on innerclass and interface
Question about Inner class
Regarding Inheritance
Inner class
Inner Classes
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:25:08.