• Post Reply Bookmark Topic Watch Topic
  • New Topic

Local Class  RSS feed

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

When the above code is executed the CTOR doesn't get printed. Can any one explain?
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think all you need to do is put the local class definition (c1 class) before the
c1 c123 = new c1();
line. At least that worked for me. I actually received a compiler error on the original source. Which I think is called a forward reference error(?).
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarma,
The code you posted does not compile on my machine:
Try this code:
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maria, I believe Tom's explanation is correct.
Your code refers to regular inner classes and Sarma's code refers to method-local inner classes.
So it looks like when you define a method-local inner class you cannot forward reference it like you can with a regular inner class.
 
I think I'll just lie down here for a second. And ponder this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!