static variable can be changed

as long as it is not “final”

public class StaticDemo {
static String name;

public static void staticVariable() {
name = name + ” ” + “Singh”;
System.out.println(“Value of static variable after method calling : ”
+ name);
}

public static void main(String[] args) {
System.out.println(“Initial value of static variable : ”
+ StaticDemo.name);
StaticDemo.name = “Bharat”;
System.out.println(“Value of static variable after initialization : ”
+ StaticDemo.name);
StaticDemo.staticVariable();
}

}

output:

Initial value of static variable : null
Value of static variable after initialization : Bharat
Value of static variable after method calling : Bharat Singh

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s