• 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

inheritance in inner classes

 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone
back to ranch after so many days
feeling good
I was playing with inner classes and found a little interesting things those are much similar to our normal classes
I am posting the code below
I don't have any question and I just want to share these interesting things
take a look at it
you will definitely like it
Happy coding
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Kharkar wrote:
I was playing with inner classes and found a little interesting things those are much similar to our normal classes
I am posting the code below
I don't have any question and I just want to share these interesting things
take a look at it
you will definitely like it



If you find this interesting... See if you can figure out how an inner class class can extend another inner class from a different outer class. Also, try to create some constructors that takes parameters too.

Henry
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear Henry sir
thank you for your suggestion
your post made me think a little deeper
here I tried to do something more interesting
I have created an interface and then implemented that in another class
thank your for your suggestion
have a nice time
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sir
also I have tried to write constructor that take arguments
but they are not accepted at all
another difference I found is that when using interface, we do not have to extend the class that contains the interface
but in case of the class we have to extend the class that contains the inner class
why is that so?
please explain
here is my code
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fixed all the compile errors in your program. In some cases, I just made changes to fix the compile error -- you'll need to fix the program itself, to do what you intended.



Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

BTW, it is much more interesting getting TestInnerClass to extend ClassInClass.InnerClass when TestClassInClass does *not* extend ClassInClass ...

Henry
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
while creating instance using the overloaded constructors why did that give errors?
I am unable to understand
how to create the instance of that class?
I really don't know
I mean I have tried definitely you know it also
but how to extend the inner class without extending the outer class ?
and why does this not apply to the interface?
please answer.
I am really eager to know
 
Ranch Hand
Posts: 63
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Kharkar wrote:while creating instance using the overloaded constructors why did that give errors?
I am unable to understand



Dear Prasad, is this related to Inner class concept ?
and if you have chance please post your works of constructor overloding along with errors , so that i can learn more.
by the way , i like your programs.

Cheers
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ravi
I feel glad that you like my programs
I will definitely do some more work on inner classes as my end semester exams are over now and I have plenty of time for preparation
if you find such interesting things, let me know
we can discuss them online
I am sending you my email ID in Personal Message
will you be my friend?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Kharkar wrote:while creating instance using the overloaded constructors why did that give errors?
I am unable to understand



You had two errors. First, you added an argument to the InnerClass class (super class) constructor, but your TestInnerClass class (sub class) constructor didn't use it. Instead, it tried to use the no-arg constructor that didn't exist. Second, you didn't instantiate the TestInnerClass correctly -- don't know why you didn't, since you did instantiated the InnerClass correctly, and it is basically done the same way.

Prasad Kharkar wrote:
but how to extend the inner class without extending the outer class ?
and why does this not apply to the interface?
please answer.
I am really eager to know



I am not sure what you mean by what applying to the interface. Can you elaborate what you mean? Your interface example looks straightforward to me.

BTW, there is also a big difference between the static inner class (more commonly know as the nested class) and the inner class. The first is much easier to understand, as it is very similar to an outclass that is merely defined in the another class. The later is much more complex -- since it needs that outer class, and can get really complex when it needs multiple outer classes (as you are trying to figure out).

Henry
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hahahaha
I have to agree that I am a fool
thank you Henry sir for pointing that out
sometimes I go blind
but I really don't know how to use the InnerClass for subclassing in another class without extending the outer class
also why does that work when we implement interface from another class
why does that not require the another class to subclass the class that has that interface?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Kharkar wrote:why does that work when we implement interface from another class



because interface dont have constructor . I ask you one thing, how do you instantiate the inner class[abstract static] which is inside an interface ?

<edit>also if the inner class[InnerClass] is static , then no need to extends the outer class[ClassInClass]</edit>
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Kharkar wrote:
but I really don't know how to use the InnerClass for subclassing in another class without extending the outer class



Here you go... The TestClassInClass modified to not extend ClassInClass, which causes some changes in the inner classes which still does inherit from each other.



Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Kharkar wrote:
also why does that work when we implement interface from another class
why does that not require the another class to subclass the class that has that interface?



I don't know why you are trying to compare the two. Interfaces and classes are not the same thing.

As from my previous post, even with inner classes, it doesn't require that the outer class be subclassed from each other. But the reason in your example, it was somewhat needed because inner classes contain a reference to its outer class, and subclassing the outer classes was one way to do it. My example was another way to do it.

As for interfaces, or even nested classes, this requirement (ref to outer class) does not exist.

Henry
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Henry sir
got it to much extent
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic