The 16 Types of JAVA Members




Each member (of a class or object) in JAVA can be either (but not both):
TYPE DESCRIPTION KEYWORD DIAGRAMED
public All classes and instances have access to the member. public drawn on the border of the large class or object rectangle, so that other classes and objects can "see" it and have access to it.
OR
private The member is available only to the class or object itself. No other classes or objects may use the member. private drawn inside the large class or object rectangle, so that no other classes or objects can "see" it or have access to it


Each member (of a class or object) in JAVA falls into one of the following categories (but not both):
TYPE DESCRIPTION KEYWORD DIAGRAMED
class the member has the scope of the entire class, and while individual objects may use the member, they will not have a copy of the member for themselves. Rather, there is only one copy of this member that is shared by all the instance objects. Class members do not have access, regardlress of visibility modifiers, to instance members. static the rectangle is drwan with right angles for corners
OR
instance the member is maintained and controlled specifically by one object.   the rectangle is drawn with rounded corners


Each member (of a class or object) in JAVA can be either a (but not both):
TYPE DESCRIPTION KEYWORD DIAGRAMED
constant the member must be given an initial definition or value and cannot be changed from that point on. final a small lock is drawn inside the rectangle
OR     A
variable the member may be changed as often as you like.    


Each member (of a class or object) in JAVA can be either a (but not both):
TYPE DESCRIPTION KEYWORD DIAGRAMED
data the member is either an Object (reference) or a primitive   the name of the member is placed above its rectangle, so that the actual value may be placed inside
OR     A
method the member is an action that can be performed (when sent a message to do so)   the name of the member is placed inside the rectangle; arguments and return values are communicated with arrows




ORDER:  There is an order in which the modifiers are specified, if at all, in a declaration statement:

 <visibilityModifier>   <staticModifier>   <constantModifier> 



This means that there are 8 different types of data members and 8 different types of method members that a class or object may have. They are as follows:

  • public <dataOrMethodName>
    each object has their own instance and any class or object has access to it


  • private <dataOrMethodName>
    each objecat has their own instance but no other classes or objects have access to it


  • public static <dataOrMethodName>
    there is only one shared copy owned by the class and any other class or object has access to it


  • private static <dataOrMethodName>
    there is only one shared copy owned by the class but no other classes or objects have access to it


  • public final <dataOrMethodName>
    each object has their own unchangeable instance, and any other class or object has access to it


  • private final <dataOrMethodName>
    each object has their own unchangeable instance, but no other classes or objects have access to it


  • public static final <dataOrMethodName>
    there is only one shared unchangeable copy, and any class or object has access to it


  • private static final <dataOrMethodName>
    there is only one shared unchangeable copy, but no other classes or objects have access to it


  • To see how these are diagrammed, please refer to the diagramming page.

    Notice that each of these are different and will have slightly different uses than the rest. For example, program-defined constants such as maximum allowed values or default values are often decalred as public static final since everyone should know about them, they apply to the whole program, and they won't ever change. In contrast, local instance variables that are used by objects just to keep track of their own data are best decalred with private.