• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the difference?

 
Guru dhaasan
Ranch Hand
Posts: 126
Java Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anton Uwe
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The go(..)-method in code 2 isn't static.
 
Guru dhaasan
Ranch Hand
Posts: 126
Java Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so the static functions will always prefixed by a static keyword
 
Jesse Custer
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 126
Java Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want a method to be static you have to use the keyword "static" as a prefix.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic