• Post Reply Bookmark Topic Watch Topic
  • New Topic

Anonymous inner classes : How to run their methods ?  RSS feed

 
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :

 
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to run the println inside main() of the classes in main(String[] args) ?
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:How do you other wise invoke the methods of an instance?
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!