You control access to classes and members in the same way:
by using an access modifier such as
public
in their declaration.
You specify a class variable or a class method by using
the static
keyword in the member's declaration. A
member that is not declared as static
is implicitly
an instance member. Class variables are shared by all instances of
a class and can be accessed through the class name as well as an instance reference. Instances of
a class get their own copy of each instance variable, which must be
accessed through an instance reference.
You create an object from a class by using the new
operator and a constructor.
The new operator returns a reference to the object that was created. You can assign the reference
to a variable or use it directly.
Instance variables and methods that are accessible to code outside of the class that they are declared in can be referred to by using a qualified name. The qualified name of an instance variable looks like this:
objectReference.variableName
objectReference.methodName(argumentList) or objectReference.methodName()
null
.