| 10 | } |
| 11 | public class StaticCount { |
| 12 | public static void main(String[] args) { |
| 13 | // TODO Auto-generated method stub |
| 14 | System.out.println("Instantiating objects and calling increment function, as well as displaying the value of count variable: "); |
| 15 | Static obj1 = new Static(); |
| 16 | obj1.increment(); // Value of count variable increased after calling the increment function on the first object |
| 17 | obj1.display(); // Displays the value of the count after incrementing |
| 18 | Static obj2 = new Static(); |
| 19 | obj2.increment(); // Value of count variable increased after calling the increment function on the second object |
| 20 | obj2.display(); // Displays the value of the count after incrementing |
| 21 | Static obj3 = new Static(); |
| 22 | obj3.increment(); // Value of count variable increased after calling the increment function on the third object |
| 23 | obj3.display(); // Displays the value of the count after incrementing |
| 24 | System.out.println("Now displaying values of the static variable count, for all the objects: "); |
| 25 | // Now, displaying value of static variable count after object instantiation for all objects |
| 26 | // Since the count variable is static, it will display the same value for all objects |
| 27 | System.out.println("The value of count for first object: "); |
| 28 | obj1.display(); |
| 29 | System.out.println("The value of count for second object: "); |
| 30 | obj2.display(); |
| 31 | System.out.println("The value of count for third object: "); |
| 32 | obj3.display(); |
| 33 | } |
| 34 | } |