Specifications

Sun Services
Java™ Programming Language
Module 7, slide 8 of 44
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Class Methods
You can invoke static methods without any instance of the
class to which it belongs:
1 public class TestCounter {
2 public static void main(String[] args) {
3 System.out.println("Number of counter is "
4 + Count2.getTotalCount());
5 Count2 counter = new Count2();
6 System.out.println(
"
Number of counter is "
7 + Count2.getTotalCount());
8 }
9}
The output of the TestCounter program is:
Number of counter is 0
Number of counter is 1