• 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

Why I cannot extend the inner class with enclosing class

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I knew this is stupid question.I tried for to find out the error message. I cannot understand anything from this below error message.

E:\java\Testaaaac.java:13: cannot reference this before supertype constructor has been called
class zz extends yy{
^
1 error

Tool completed with exit code 1
The code is below


If you look the above code , class yy extends xx. But why I cannot extend the class zz from class yy.

but the below code is compiling fine.



[ March 17, 2005: Message edited by: adiratha abhivachan ]
[ March 17, 2005: Message edited by: adiratha abhivachan ]
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An inner class declaration is treated as a fully qualified member of the enclosing class.
Therefore, the inner class definition is only available after the superclass constructors have completed (as with data members).

As a result you get an error trying to derive one of your inner classes from another.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can some one explain the actual usage of inner classes in real scenario ?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Several reasons. I use them to for implementing threads by extending Runnable in situations where the actual functionality is useless outside the class using them.
Another use could be returning objects from a factory. By making them inner classes you ensure that nothing outside the factory can create instances (by making the factory an abstract class with a static factory method).
Listeners are another classic example.
 
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic