Discuss about an access modifier


Complete the following:

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.

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);
}
}

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Discuss about an access modifier
Reference No:- TGS01934666

Now Priced at $25 (50% Discount)

Recommended (94%)

Rated (4.6/5)