Variable question

  • Thread starter Thread starter Keith Smith
  • Start date Start date
K

Keith Smith

What is the difference between these two statements?

public static string var1;

public string var1;
 
hi

public static string var1;

Static member of a class is shared by all instances of the class.
A static field is not part of a specific instance; instead, it identifies
exactly one storage location. No matter how many instances of a class are
created, there is only ever one copy of a static field for the associated
application domain.


public string var1;
This decalration is an instance variable and
Instance variable can have different values for different objects.
An instance field belongs to an instance. Specifically, every instance of a
class contains a separate set of all the instance fields of that class.


regards
Ansil
Trivandrum
 
Back
Top