What is a method declaration without the implementation?

A good answer might be:

It is simply an access modifier, return type, and method signature followed by a semicolon.

Example interface

Here is an example interface definition:

interface MyInterface
{
  public final int aConstant = 32;        // a constant
  public final double pi = 3.14159;       // a constant

  public void methodA( int x );           // a method declaration
  double methodB();                       // a method declaration
}

(The constants don't have to be separated from the methods, but doing so makes the interface easier to read.) A method in an interface cannot be made private.

When a class definition implements an interface:

  • It must implement each method in the interface.
  • Each method must be public (even though the interface might not say so.)
  • Constants from the interface can be used as if they had been defined in the class. (They should not be re-defined in the class.)

QUESTION 3:

interface SomeInterface
{
  public final int x = 32;
  public double y;

  public double addup( );
}

Inspect the interface at left.

Is it correct?

Click here for a


Click Here after you have answered the question