Non Static Variables
Can be accessed only by creating an instance.
It will be not be updated when a new instance of the object is created.
public class NonStaticVariables {
public NonStaticVariables() {
instancecount++;
}
private int instancecount;
public static void main(String args[]){
NonStaticVariables nsv=new NonStaticVariables();
System.out.println(nsv.instancecount);
NonStaticVariables nsv1=new NonStaticVariables();
System.out.println(nsv1.instancecount);
}
}
It will be not be updated when a new instance of the object is created.
public class NonStaticVariables {
public NonStaticVariables() {
instancecount++;
}
private int instancecount;
public static void main(String args[]){
NonStaticVariables nsv=new NonStaticVariables();
System.out.println(nsv.instancecount);
NonStaticVariables nsv1=new NonStaticVariables();
System.out.println(nsv1.instancecount);
}
}
Comments
Post a Comment