File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes   kathy sierra question doubt scjp 1.6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "  kathy sierra question doubt scjp 1.6" Watch "  kathy sierra question doubt scjp 1.6" New topic
Author

kathy sierra question doubt scjp 1.6

dilip kumarr
Greenhorn

Joined: Jan 31, 2010
Posts: 6

Anyone please explain this code in detail ., i'm not able to understand ...
thanks in advance.

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Its very simple, you are calling a non-static method directly from a static method, this is not allowed. You need an instance of Frodo/Hobbit class to call the countGold method from the main method...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
dipayan chatterjee
Ranch Hand

Joined: Oct 03, 2007
Posts: 47
Hi dilip

countGold(myGold, 6) basically resolves to this.countGold(myGold,6) and since the main method is static it means it is not running on any instance of class Frodo hence there exsists no object so cant invoke the instance method countGold(intx,inty) .

This is the basic reason why calling a non-static method directly from a static method, this is not allowed.


Hth


SCJP1.4 , gearing up for SCWCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: kathy sierra question doubt scjp 1.6