Variables can be Static or Instance Variable depending upon our usage.
Suppose the value is constant throughout the class we can define a static variable
In case the value of variable keeps changing every time we call the class then its is called as Instance variable
Example we have a class called bus
if there is a variable defined for driver and passengers
bus1
the value of driver is always =1 so we can define as static
public int static driver=1;
the value of passenger keeps changing so its defined as instance
public int passenger=20;
again for bus2
the value of driver is always =1 so we can define as static
public int static driver=1;
the value of passenger keeps changing so its defined as instance
public int passenger=30;
No comments:
Post a Comment