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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Extend an inner class by code outside the top level class

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Report post to moderator

For the above code, the compile time error generated is :
No enclosing instance of type Main is available due to some intermediate constructor invocation.
Does this error indicate that there is some other way to extend an inner class by code outside the top level class?
Can someone help by explaining the error statement?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
  • Report post to moderator

Cyril Sadasivan wrote:
No enclosing instance of type Main is available due to some intermediate constructor invocation.


fine. when you say , then compiler define a default constructor for you as

note here super() means you are accessing the Inner class constructor directly, which is not possible since inner class bound to an outer class instance.
i.e, to access non-static inner class member you should access via outer class instance. hence access inner class constructor as some thing like below
 
author
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not cross post, it wastes people's time and effort...

https://coderanch.com/t/588820/java/java/Extend-inner-class-code-outside

Henry
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic