Counting access errors in a checkout class

The following two classes are in different packages:


Java
package shop;

public class Item {
    private double price;
    int stock;
    protected String sku;
    public String label;

    public double getPrice() { return price; }
    void restock(int n) { stock += n; }
}


Java
package app;

import shop.Item;

public class Checkout {
    public void run(Item it) {
        String a = it.label;
        int b = it.stock;
        String c = it.sku;
        double d = it.price;
        double e = it.getPrice();
        it.restock(5);
    }
}


How many of the six statements in run fail to compile because of access rules? Give your answer as a whole number.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Access Modifiers Questions: