Static Variables
- Can Be Accessed directly in the main method.
- Static instance variable will be updated on creating a new instance of the object.
public class StaticVaribles {
public StaticVaribles() {
instancecount++;
}
private static int instancecount;
public static void main(String args[]){
System.out.println(instancecount);
StaticVaribles sv=new StaticVaribles();
System.out.println(instancecount);
StaticVaribles sv1=new StaticVaribles();
System.out.println(instancecount);
}
}
/*output
run:
instancecount->0
instancecount->1
instancecount->2
*/
Comments
Post a Comment