No. Variables (such as y
)
cannot be put in an interface.
Only constants and methods.
interface SomeInterface
{
public final int x = 32;
public double y;
public double addup( );
}
A class definition must always extend one parent, but it can implement zero or more interfaces:
class SomeClass extends Parent implements SomeInterface { ordinary class definition body }
The body of the class definition is the same as always. However, since it implements an interface the body must have a definition of each of the methods from the interface. The class definition can use access modifiers as usual. Here is a class definition that implements three interfaces:
public class BigClass extends Parent implements InterfaceA, InterfaceB, InterfaceC { ordinary class definition body }
Now BigClass
must provide a method definition for every method
in each of the interfaces.
Any number of classes can implement the same interfaces.
Here is another class definition:
public class SmallClass implements InterfaceA { ordinary class definition body }