go to previous page   go to home page   go to next page highlighting

Answer:

No. An interface includes only constants and method headers.


Interface Definition

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.


QUESTION 3:

(Thought Question: ) Why cannot the methods in an interface be private?


go to previous page   go to home page   go to next page