folks,
i am trying to learn the subtle differences between the different sort of variables in
java. the first two that i have tackled are,
class variables and instance variables. from what i have understood, please go through the code that i wrote and tell me if my understanding of this code is correct or not.
public class Example
{
String s = "This is a string" ;
}
the attribute "s" defined above in the Example class is a class variable. all instances of Example will have a String attribute "s" whose value would be "This is a string".
is it advisable to put a static qualifier on s? if yes why so?
public class
Test {
public static void main( String args[] )
{
Example exampleInstance = new Example() ;
System.out.println( exampleInstance.s ) ;
}
}
in the above code, exampleInstance is an instance of the class Example. therefore exampleInstance is an instance variable of type Example which has a class variable s.
is my understanding on this correct?