Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Nested Class - Issue  RSS feed

 
Mark Henryson
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The code bolded in the above pgm are not working. Whether the instance of 'a'(top-level class) dosen't have access to the methods in the Nested class.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

There are two different problems here, but they're both variations on a theme.

methodbb() is an instance method of class aa.bb; therefore you need an instance of this class to call the method. If it were a static method, you could call it as

aa.bb.methodbb()

but since it's an instance method, you need an instance, like in your variable "b" in main.

Now the other line: methodaa() is an instance method of aa, so you need an instance of aa to call it. Because bb is a static class, there's no instance of aa associated with it. If bb were not marked static, this would work -- although then your initialization of variable b wouldn't work as written, because when constructing a bb you'd need to supply an aa.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!