Each class in Java defines a namespace which allows functions and variables in separate, unrelated classes to share the same name. When identifying a function or variable in Java, the namespace must be expressed, or implied using an import directive. For example, the method Integer.toString() is distinct from Long.toString(). Java packages similarly allow distinct classes and interfaces to share the same name. For example, the name Object could refer to either java.lang.Object or org.omg.CORBA.Object.

In C, all functions are global, and must share a single namespace (i.e., one per program). Global variables can also be declared and defined, and they also share that namespace. Care must be taken in choosing names for functions in large projects, and often a strategy of using a common prefix for groups of related functions is employed. For example, WSA prefixes most of the WinSock functions.

Note that other namespaces exist in a C progam: a single namespace is shared by the tags of all structures, unions and enumerations; each structure and union holds a unique namespace for its members; each block statement holds a namespace for local variables.