Pages

Jun 5, 2015

[CS61B-2015] Notes for class 2-Defining and using classes



Static vs. Non-static
A class may have a mix of static and non-static members.

  • A variable or method defined in a class is also called a member of that class.
  • Static members are accessed using class name, e.g. ClassName.StaticMember.
  • Non-static members cannot be invoked using class name: Dog.makeNoise().
  • Static methods must access instance variables via a specific instance, e.g. an object.
  • Static members are shared in a class.

No comments:

Post a Comment