Question on static methods

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All,

Consider the following code block...

Public class ClassA
{
public int A;
public int B;

public static void MethodA()
{
. .. ......
}
}

If two threads execute the method A, would they be having two different
copies of A and B variables?

Thanks!!
 
No. When you call a static method, it does not create an instance of ClassA
and you cannot access instance variables (such as A and B) from within a
static method.
 
The question is not exactly correct. A static method can't use non-static
members of the class. You would have to declare A and B as static. And then
the answer is no, there will be only one instance.

Eliyahu
 
Back
Top