Both. Usually objects in the world can be regarded in several ways.


With object oriented programming, you define software objects that mimic "real world" objects. This makes programs easier to think about and more reliable. In the real world, you often think about an object in several different ways. You can think of your car as a vehicle or as taxable property. It would be convenient if software objects, also, could be thought of in several ways. But a Java object belongs to just one class.

An interface describes aspects of a class other than those that it inherits from its parent. An interface is a set of requirements that the class must implement.

An interface is a list of constants and method declarations. The method declarations DO NOT include an implementation (there is no method body). A class that implements an interface must implement each of the methods listed in the interface.

A class can extend one parent class to inherit the methods and instance variables of that parent. A class can also implement an interface to gain additional methods and constants. However, the additional methods must be explicitly written as part of the class definition. The interface is a list of requirements that the class definition must explicitly meet (through code, not through inheritance).

For example, a class Car might extend the Vehicle class. This gives it all the methods and instance variables of Vehicle, by inheritance. If Car also implements the Taxable interface, then its definition must contain code for all the methods listed in Taxable.


Can an interface list instance variables?