Example 1: Which access modifier (public, private, protected, default) would you use on a data field in the following cases?
a. You plan to inherit from this class from without the package.
b. You want only those classes within the package to have access to this field.
c. You want to restrict access to within the class itself.
d. The client should have access to this field.
Example 2: Examine the following driver for classes Book and LibBook and determine what is printed
// Class TestBook is a driver for classes
// Book and TestBook
public class TestBook
public static void main(String args)
new LibBook("How to Solve It",
new Book("Programming and Problem Solving with Java",
"Nell Dale and Chip Weems",
System.out.println("Book object: " + "n" + second);
System.out.println("LibBook object: " + "n" + first);
The output ...
The expert examines inheritance, polymorphism and scope.