aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the difference? 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is the difference?" Watch "what is the difference?" New topic
Author

what is the difference?

Guru dhaasan
Ranch Hand

Joined: Sep 13, 2006
Posts: 126

Lets for example we have the following 2 different code:

code1:


and the next code

code2:



My Question is:
Why in code 1, we are calling foo(o) and not o.foo(o) like we have c1.go(c2) in code2 (since both are static functions)

Thanks in Advance,
Cheers
Gurudoss


Thanks, Shiv
SCJP, OCE - JSP & Servlets Developer
Anton Uwe
Ranch Hand

Joined: Jan 10, 2007
Posts: 122
The go(..)-method in code 2 isn't static.
Guru dhaasan
Ranch Hand

Joined: Sep 13, 2006
Posts: 126

so the static functions will always prefixed by a static keyword
Jesse Custer
Ranch Hand

Joined: Feb 07, 2007
Posts: 45
In code 1 you can not call o.foo(o) because o is an Object of type 'Object' and does not have the method 'foo'.

'foo' is a method of the class DoesNotPrint_null and it needs to be static to be called from the static Main.

Grtz
Guru dhaasan
Ranch Hand

Joined: Sep 13, 2006
Posts: 126

Thanks Koen Appermont.

But one more question from my side is: Do the static method will always be prefixed by static keyword in all occasions?
Anton Uwe
Ranch Hand

Joined: Jan 10, 2007
Posts: 122
If you want a method to be static you have to use the keyword "static" as a prefix.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: what is the difference?