No. An interface includes only constants and method headers.
An interface looks like the following.
interface InterfaceName { constant definitions method headers (without implementations). }
A method header is an access modifier, a return type, the method name, a parameter list followed by a semicolon. You can put an interface in its own source file or include it with other classes in a source file. In either case, the source file ends with the extension .java
The methods in an interface are public
by default, so you can omit public
from the method headers.
The methods cannot be private
and cannot be protected
.
An interface looks somewhat like a class definition. But no objects can be constructed from it. However, you can define a class that implements an interface, and once you have done that you can construct objects of that class.
A class implements an interface by doing this:
class SomeClass extends SomeParent implements interfaceName { }
A class extends just one parent, but may implement several interfaces.
(Thought Question: ) Why cannot the methods in an interface be private
?