Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
Programmer Certification (OCPJP)
enclosing class in a construcotr valid or not?
nagaraj raja
Ranch Hand
Posts: 36
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public class _test{ _test(){ class ctest{ void show(){ System.out.println("SHOW"); } } } public static void main(String[] args){ //how to call show() } }
reubin haz
Ranch Hand
Posts: 287
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
ctest object may only be created within _test() method because its a local inner class
SCJA, SCJP5.0, SCBCD, SCWCD
vinuharan haran
Ranch Hand
Posts: 64
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
Here is a way to call the method declared in the innerclass in the constructor.
public class _test { _test() { class ctest { void show() { System.out.println("SHOW"); } } ctest c=new ctest(); c.show(); } public static void main(String[] args) { _test t=new _test(); } }
It is perfectly legal to create a local inner class in the constructor.
Hope this helps...
thanks,
vinu.
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Inner Class Names
Finding a language setting or locale of the keyboard
JSF selectManyListbox Issue?
selectManyListbox Issue
i implemented interface in anonymous class then it shows compiler error why
More...