Hi
I'm a newbie in Java.
What's the difference between "public method" & "public static
method"?
thanks.
Mike
Daniel Pitts - 17 Apr 2007 08:03 GMT
> Hi
>
[quoted text clipped - 5 lines]
>
> Mike
While I don't mind answering a few newbie questions, I suggest you
start READING the book that you so far seem to be SCANNING.
Last answer from me for your newbie questions.
they are both accessible to all other classes, but the static method
is not associated with any particular instance of that class, and can
be called without a reference to an instance of that class.
Ian Wilson - 17 Apr 2007 10:37 GMT
> I'm a newbie in Java.
> What's the difference between "public method" & "public static
> method"?
You may find it better to use a search engine for these sorts of simple
question:
http://www.google.com/search?q=static+method
The first two items listed provide an explanation with examples. I
suspect you are unlikely to get a better answer here.
If you Googled and still have questions, ask here (or perhaps better in
in comp.lang.java.help) but mention that you tried googling, so that
people here may be less irritated by a seeming lack of effort on your part.
Chris Dollin - 17 Apr 2007 11:13 GMT
> I'm a newbie in Java.
> What's the difference between "public method" & "public static
> method"?
(a) Doesn't your Java book tell you?
(b) A "public static" method is both public and static. A method that
is "public" but not "static" is public but not static.

Signature
"Based on their behaviour so far -- I have no idea." /Sahara/
Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England
CodeForTea@gmail.com - 17 Apr 2007 13:02 GMT
> > I'm a newbie in Java.
> > What's the difference between "public method" & "public static
[quoted text clipped - 10 lines]
> Hewlett-Packard Limited registered no:
> registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England
public class TestStatic {
int value;
public TestStatic(int v) {
value = v;
}
public int getCubeCalue() {
return value * value *value;
}
public static int getSquareValue(int i) {
return i * i;
}
public static void main(String[] args ) {
int i = 5;
TestStatic test = new TestStatic(i);
// in calling the getCubeCalue I did use test
// (instance of TestStatic)
// for invoking non static methods.
System.out.println("Cube value of " + i
+ " = " + test.getCubeCalue());
i = 10;
// in calling the getSquareValue I did not use test
// (instance of TestStatic)
System.out.println("Square value of " +
" = " + TestStatic.getSquareValue(i));
}
}