B Solutions

Introducing Interfaces

Solution 2.1

(from page 12)

An abstract class with no nonabstract methods is similar to an interface in terms of its utility. However, note the following.

•    A class can implement any number of interfaces but can subclass at most one abstract class.

•    An abstract class can have nonabstract methods; all the methods of an interface are effectively abstract.

•    An abstract class can declare and use fields; an interface cannot, although it can create static final constants.

•    An abstract class can have methods whose access is public, protected, private, or none (package). An interface’s methods are implicitly public.

•    An abstract class can define constructors; an interface cannot.

Get Design Patterns in Java™, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.