How do I identify which is static and which is non static method?

I have a question which is how can i justify which is static and which is non static method in a program? I need to explain why ? I think it the version 2 which is static. I can only said that it using using a reference. But am I correct or ? Please advise....

if I have the following :

class Square

{

private double side;

public Square(double side)

{ this.side = side;

}

public double findAreaVersion1()

{ return side * side;

}

public double findAreaVersion2(Square sq)

{ return sq.side * sq.side;

}

public void setSide(double s)

{ side = s;

}

public double getSide()

{ return side;

}

} //class Square

Message was edited by:

SummerCool

[783 byte] By [SummerCoola] at [2007-11-27 11:19:31]
# 1

public void foo() {} // non-static

public static void bar() {} // static

jverda at 2007-7-29 14:37:12 > top of Java-index,Java Essentials,Java Programming...
# 2

Dear SummerCool

always put in mind that static methods are there to help us using them without creating an instance of the class they are in..

take for example method

Integer.parseInt(String s);

you can see that we can call this method without making instance of class Integer,,

later when you start writing your own code well, you can identify the need of static methods and non-static methods...

Q.Najjar (^_^);

QussayNajjara at 2007-7-29 14:37:12 > top of Java-index,Java Essentials,Java Programming...
# 3

> public void foo() {} // non-static

> public static void bar() {} // static

Well, who'd have thought it?!

kind regards,

Jos ;-)

JosAHa at 2007-7-29 14:37:12 > top of Java-index,Java Essentials,Java Programming...
# 4

> I have a question which is how can i justify which is

> static and which is non static method in a program? I

> need to explain why ? I think it the version 2 which

> is static. I can only said that it using using a

> reference. But am I correct or ? Please advise....

If I am reading this correctly, that you think that your version 2 is a static method, then you are wrong and need to review your java textbook on static vs non-static functions and variables.

petes1234a at 2007-7-29 14:37:12 > top of Java-index,Java Essentials,Java Programming...