This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Anonymous inner classes : How to run their methods ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Anonymous inner classes : How to run their methods ?" Watch "Anonymous inner classes : How to run their methods ?" New topic
Author

Anonymous inner classes : How to run their methods ?

Rahul Sudip Bose
Ranch Hand

Joined: Jan 21, 2011
Posts: 637

The code below compiles. But how do i execute the methods of my anonymous inner classes ? The method name is public void main(){.....}
This code is only for learning, doesnt do anything useful.



here is the current output :



SCJP 6. Learning more now.
Mohamed Sanaulla
Bartender

Joined: Sep 08, 2007
Posts: 2946
    
  15

How do you other wise invoke the methods of an instance? In the anonymous inner class syntax- You are actually extending the Dream class and then creating an instance of that extended class.


Mohamed Sanaulla | My Blog
Rahul Sudip Bose
Ranch Hand

Joined: Jan 21, 2011
Posts: 637

how to run the println inside main() of the classes in main(String[] args) ?
Mohamed Sanaulla
Bartender

Joined: Sep 08, 2007
Posts: 2946
    
  15

Mohamed Sanaulla wrote:How do you other wise invoke the methods of an instance?
Rahul Sudip Bose
Ranch Hand

Joined: Jan 21, 2011
Posts: 637

Ok, got it. Instances of the anonymous inner classes that extend a class (or implement an interface) can be accessed only by using a reference of the super-type (hope this makes sense).

This is the code :


PS : so many rules to remember. Are there any condensed notes/flash-cards that help in remembering them ?

here is the code finally : dont try to make sense of the random strings


output :





Mohamed Sanaulla
Bartender

Joined: Sep 08, 2007
Posts: 2946
    
  15

Rahul Sudip Bose wrote:
PS : so many rules to remember. Are there any condensed notes/flash-cards that help in remembering them ?

Practice would make you familiar with them. You can create your own notes/flash-cards and share it here There are a few notes available. You might find them in ScjpFaq You can google for "Jonathan Giles scjp notes"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Anonymous inner classes : How to run their methods ?
 
Similar Threads
Anonymous Inner Class Question
a simple brainer on inner classes
Anonymous Inner Classes
Anonymous Inner class
Anonymous inner class