It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Local Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Local Class" Watch "Local Class" New topic

Local Class

Sarma Lolla
Ranch Hand

Joined: Oct 21, 2002
Posts: 203

When the above code is executed the CTOR doesn't get printed. Can any one explain?
Tom Adams
Ranch Hand

Joined: Feb 07, 2003
Posts: 56
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(?).

Maria Garcia
Ranch Hand

Joined: Jul 14, 2002
Posts: 86
The code you posted does not compile on my machine:
Try this code:

SCJP 1.4
Dan Culache
Ranch Hand

Joined: Jan 24, 2003
Posts: 70
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 agree. Here's the link:
subject: Local Class
It's not a secret anymore!