GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Java/Programs/StaticCount.java at main · arshcoder13/Java

Expand file tree

/

StaticCount.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
34 lines (34 loc) · 1.53 KB
/

StaticCount.java

Copy path

File metadata and controls

34 lines (34 loc) · 1.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package staticCount;
class Static {
static int count = 0;
void increment() {
count++;
}
void display() {
System.out.println(count);
}
}
public class StaticCount {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Instantiating objects and calling increment function, as well as displaying the value of count variable: ");
Static obj1 = new Static();
obj1.increment(); // Value of count variable increased after calling the increment function on the first object
obj1.display(); // Displays the value of the count after incrementing
Static obj2 = new Static();
obj2.increment(); // Value of count variable increased after calling the increment function on the second object
obj2.display(); // Displays the value of the count after incrementing
Static obj3 = new Static();
obj3.increment(); // Value of count variable increased after calling the increment function on the third object
obj3.display(); // Displays the value of the count after incrementing
System.out.println("Now displaying values of the static variable count, for all the objects: ");
// Now, displaying value of static variable count after object instantiation for all objects
// Since the count variable is static, it will display the same value for all objects
System.out.println("The value of count for first object: ");
obj1.display();
System.out.println("The value of count for second object: ");
obj2.display();
System.out.println("The value of count for third object: ");
obj3.display();
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.