Lecture 15 - 02/22

Packages, Access Control, Objects

Packages, JAR files, Build Systems

Access Control

Access is based only on static types:
Let us have the following code:

package universe;
public interface BlackHole {
void add(Object x);

Note that add method is actually of public access, as it inherits the modifier of the interface it's defined in because it lacks a modifier. In cases like this, the lack of a modifier doesn't indicate packageprivate (Java's weird like that)

package universe;
public class CreationUtils {
public static BlackHole hirsute() {
return new HasHair();
package universe;
class HasHair implements BlackHole {
Object[] items;
public void add(Object o) { ... }
public Object get(int k) { ... }

And lastly the file below (note this is in the default package, not universe package):

import static CreationUtils.hirsute;
class Client {
void demoAccess() {
BlackHole b = hirsute();
HasHair hb = (HasHair) b;

Access control at top level (on entire interface/class):

Access control purpose: