aspose file tools*
The moose likes Beginning Java and the fly likes Implementing Interface Using Anonymous Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Implementing Interface Using Anonymous Class" Watch "Implementing Interface Using Anonymous Class" New topic
Author

Implementing Interface Using Anonymous Class

Sridhar Iyer
Greenhorn

Joined: Feb 21, 2011
Posts: 5

I don't seem to understand why "Cooking" is not being printed in the output for the following code. Can someone please explain me






Thanks
Sridhar
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

So your main method ends up executing the following line:


That creates a new Cookable object correctly. But nowhere do you tell it to execute its cook() method. If you want the output, try adding the line cookable.cook() after line 18.

By the way, the code would be a bit easier to read if you followed the Java conventions on capitalisation. The method Cooking() should really be cooking().
Sridhar Iyer
Greenhorn

Joined: Feb 21, 2011
Posts: 5

Thanks Matthew. Made the changes.

Thanks
Sridhar
 
Consider Paul's rocket mass heater.
 
subject: Implementing Interface Using Anonymous Class