【正文】
disonWesley. All rights reserved. Implementation of an Interface 138 Copyright 169。 2021 Pearson AddisonWesley. All rights reserved. Interfaces ? To implement an interface, a concrete class must do two things: 1. It must include the phrase implements Interface_Name at the start of the class definition – If more than one interface is implemented, each is listed, separated by mas 2. The class must implement all the method headings listed in the definition(s) of the interface(s) ? Note the use of Object as the parameter type in the following examples 136 Copyright 169。 2021 Pearson AddisonWesley. All rights reserved. Interfaces ? An interface and all of its method headings should be declared public – They cannot be given private, protected, or package access ? When a class implements an interface, it must make all the methods in the interface public ? Because an interface is a type, a method may be written with a parameter of an interface type – That parameter will accept as an argument any class that implements the interface 134 Copyright 169。 2021 Pearson AddisonWesley. All rights reserved. Interfaces ? An interface serves a function similar to a base class, though it is not a base class – Some languages allow one class to be derived from two or more different base classes – This multiple inheritance is not allowed in Java – Instead, Java39。Chapter 13 Interfaces Copyright 169。 2021 Pearson AddisonWesley. All rights reserved. Interfaces ? An interface is something like an extreme case of an abstract class – However, an interface is not a class – It is a type that can be satisfied by any class that implements the interface ? The syntax for defining an interface is similar to that of defining a class – Except the word interface is used in place of class ? An interface specifies a set of methods that any class that implements the interface must have – It contains method headings and constant definitions only – It contains no instance variables nor any plete method definitions 132 Copyright 169。s way of approximating multiple inheritance is through interfaces 133 Copyright 169。 2021 Pearson AddisonWesley. All rights reserved. The Ordered Interface 135 Copyright 169。 2021 Pearson AddisonWesley. All rights reserved. Implementation of an Interface 137 Copyright 169。 2021 Pea