Site hosted by Angelfire.com: Build your free website today!
 

Class members

  • Class members (variables and methos) are prefaces with the keyword static.

  • Class methods can only access class members, but instance methods can access both class or instance variables.

  • If you want to access a class member from another class, use either the class name or the object name.

Note

Class members maintain only one copy in memory. Therefore, even though you may have instantiated many instances of a class, each member that is declated as static will be stored across all instances of that class. This is similar to the concept of global variables, but the word global is not acceptable in OO concepts.

class MathClassMember {
    static void main(String[] args) {
        double deg = Double.parseDouble(args[0]); //class method parseDouble
        System.out.println("sin(" + deg + ") = " +
            Math.sin(deg));
    }
}