Understanding Java Access Modifiers

1

Select different access modifiers for the class Movie and its members from the drop down menus.

2

Hover over, or touch, the colored dots for more information.

cinema

package cinema;

class Movie {

    String movieName;

    void changeMovie() {}

}

package cinema;

public class MovieTicket extends Movie {

    public MovieTicket() {

     
movieName = "Vertigo";

     
changeMovie();

    }

}

package cinema;

public class Projectionist {

    public Projectionist() {

     
Movie movie = new Movie();

     
movie.movieName = "Vertigo";

     
movie.changeMovie();

    }

}

mall

package mall;

import cinema.Movie;

public class Moviegoer extends Movie
{

    public Moviegoer() {

     
movieName = "Vertigo";

     
changeMovie();

     
Movie movie = new Movie();

     
movie.movieName = "Vertigo";

     
movie.changeMovie();

    }

}

package mall;

import cinema.Movie;

public class VendingMachine {

    public VendingMachine() {

     
Movie movie = new Movie();

     
movie.movieName = "Vertigo";

     
movie.changeMovie();

    }

}

Visibility of the class Movie's variable movieName
Modifier Movie MovieTicket Projectionist Moviegoer VendingMachine
public
protected
no modifier
private
Visibility of the class Movie's method changeMovie
Modifier Movie MovieTicket Projectionist Moviegoer VendingMachine
public
protected
no modifier
private

Download the example Java source code files.