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)
Anonymous Inner Class Problem
Sun LiWei
Ranch Hand
Posts: 49
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Are there some way to make the anonymous inner class to call the constructor???
new Thread() { { //super("Anonymous Thread"); } public void run() { System.out.println("I have no name"); } }.start();
Ashish Hareet
Ranch Hand
Posts: 375
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Sun,
Try this code
class Lithium { Lithium(){ System.out.println("I'm the no-args kind"); } Lithium(String str){ System.out.println("I'm the String kind"); } Lithium(int x){ System.out.println("I'm the int kind"); } public static void main(String [] ka){ new Lithium(){ // I call the no-args constructor }; new Lithium ("Some String"){ // I call the String constructor }; new Lithium(100){ // I call the int constructor }; } };
HTH
Ashish H.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
A question about anonymous class???
Inner classes vs. HAS-A
Q: Anonymous inner class extending outer class
What is this technique called?
Passing an object to a method.
More...