AP® Computer Science A glossary

Access modifier

Also called: public, private

Course: AP® Computer Science A Shows up in: Unit 3: Class Creation

The keywords public and private, which control whether classes, data, constructors and methods can be used from outside the declaring class.

Appears in the course and exam description (CED): 3.3.A.13.3.A.23.3.A.33.3.A.6

In AP® code, classes and constructors are public, instance variables are private unless the specification says otherwise, and methods are public or private. Local variables and parameters can never have an access modifier.

public class Safe
{
    private int code;      // only Safe's own code can use it

    public Safe(int c)     // anyone can create a Safe
    {
        code = c;
    }

    public boolean opens(int guess)
    {
        return guess == code;
    }
}
Learn it properly, with a checkpoint 3.3 Anatomy of a Class

Related terms

Was this page helpful?

No names are ever shown, and every public comment is checked by us first. Please do not include personal details. To get a reply, email [email protected].

↑ Top

Enlarged view of the selected figure