Blakes 21 Days Chapter 6 Document


Day 6, Packages, Interfaces, and Other Class Features

Modifiers

Access Control for Methods and Variables

Default Access

Private Access

Public Access

Protected Access

Comparing Levels of Access Control

TABLE 6.1 The Different Levels of Access Control
Visibility Public Protected Default Private
From the same class Yes Yes Yes Yes
From any class in the same package Yes Yes Yes No
From any class outside the package Yes No No No
From a subclass in the same package Yes Yes Yes No
From a subclass outside the same package Yes Yes No No

Access Control and Inheritance

Accessor Methods

Static Variables and Methods

First Program

Listing 6.1

210
211
212
213

Run Program

Figure 6.1 goes here, but you can see my "Output" panel just above.

Final Classes, Methods, and Variables

Variables

Methods

Classes

Abstract Classes and Methods

Packages

The import Declaration

Class Name Conflicts

Creating Your Own Packages

Picking a Package Name

Creating the Folder Structure

Figure 6.2 goes here

Adding a Class to a Package

Packages and Class Access Control

Interfaces

The Problem of Single Inheritance

Interfaces and Classes

Implementing and Using Interfaces

Implementing Multiple Interfaces

Other Uses of Interfaces

Creating and Extending Interfaces

New Interfaces

Methods Inside Interfaces

Extending Interfaces

Creating an Online Storefront (Second Program)

Listing 6.2

Figure 6.3 goes here

Explanation

Third Program

Listing 6.3

Explanation

Listing 6.4

Explanation

Figure 6.4 goes here



Summary

Q & A

Quiz - Questions

  1. What packages are automatically imported into your Java classes ?
    1. None
    2. The classes are stored in the folders of your Classpath
    3. The classes in the java.lang package
  2. According to the convention for naming packages, what should be the first part of the name of a package you create ?
    1. Your name followed by a period
    2. Your top-level Internet domain followed by a period
    3. The text java followed by a period
  3. If you create a subclass and override a public method, what access modifiers can you use with that method ?
    1. public only
    2. public or protected
    3. public, protected, or default access

Answers

  1. C. All other packages must be imported if you want to use short class names
  2. B. This convention assumes that all Java package developers will own an Internet domain
  3. A. All public methods must remain public in subclasses.

Certification Practice

  1. Which instance variables are visible in the EvenMoreInformation() class ?
    1. quantity, duration, rate, and average
    2. quantity, duration, and rate
    3. quantity, duration, and average
    4. quantity, rate, and average

Exercise