What difference between interface inheritance

Interface inheritance: interface, implements

Programming - Java II SS 2001

Interface inheritance:

interface, implements

• Java does not recognize multiple inheritance in the sense of

Implementation inheritance (extends)

• By inheritance via implements can interfaces

be inherited.

• Definition of interfaces:

interface instead of class

• Implementation of interfaces:

implements instead of extends

• Differences between inheritance and interfaces:

• A class can have several interfaces, but always

only have a direct upper class

• An interface does not have an implementation, it has

defines only one interface.

• Upper class implemented generally the common

Behavior of multiple subclasses

• Interface establishes a common interface

firmly without building a hierarchy

W. Suess 1 interface


Programming - Java II SS 2001

Example:

// Definition of the interface

interface CD player {

public void playNextTitle ();

}

interface Tuner {

public void getNextRadioStation ();

}

// A server implements the interfaces

class stereo system extends electrical equipment

implements CD player, tuner, etc. {

// The implementation was promised.

// Now it is requested by the Java compiler!

public void playNextTitle () {

// This is where the implementation goes!

}

public void getNextRadioStation () {

// This is where the implementation goes!

}

}

// A client is using the devices

class living room {

... some method ...

// Buy a new device

Stereo system hifikiste = new stereo system (...);

// The device promises a lot ...

.....

hifikiste.playNextTitle ();

hifikiste.getNextRadioStation ();

....

}

W. Suess 2 interface


Programming - Java II SS 2001

public interface Loud animal {

public void returnsSound ();

}

Example:

public class cat implements Loud animal {

public void givesLaut () {

System.out.println ("Meow!");

}

}

public class dog implements Loud animal {

public void givesLaut () {

System.out.println ("Wau wau!");

}

}

public class cat music {

public static void main (String [] args) {

}

}

Loud animal tier1 = new cat ();

Loud animal tier2 = new dog ();

for (int i = 1; i


Programming - Java II SS 2001

• Interface: contract between client (client)

and contractor (server).

• Implementation of the functionality by the

Contractor (server).

• Users (clients) do not need any knowledge of implementations

from any objects, rather

only the description of the interface.

• The provider of a service (server) implemented

the service by the class from the interface

is derived. After that, all methods of the

Service overwritten.

• In the sense of this theory, a class can have several

Implement interfaces.

W. Suess 4 Interface

You have already reported this magazine
Thank you for your help in keeping this platform clean.
The editorial team will take a look at it as soon as possible.

Send the magazine by email

Are you sure you want to delete the template?

There is no download available for this magazine

Magazine: Interface inheritance: interface, implements