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
import java.util.Scanner;
public class TestBook
{
public static void main(String[] args)
{
LibBook first;
Book second;
first =
new LibBook("How to Solve It",
"G. Polya",
"0-691-02356-5",
2, 511);
second =
new Book("Programming and Problem Solving with Java",
"Nell Dale and Chip Weems",
"10: 0-7637-3402-0");
System.out.println("Book object: " + "n" + second);
System.out.println("LibBook object: " + "n" + first);
}
}