View RSS Feed

Java Object

What Is an Interface?

Rate this Entry
by , 04-26-2012 at 05:33 PM (775 Views)
As it has been discussed, objects show the interaction which takes place with outer world via certain methods being exposed by them. Interface of object is formed by the methods, with outer world; buttons which are present at television set are the interface b/w electrical wiring and you. Power button is pressed to turn it off or on.

Its common form shows that interface is related method’s group along with empty bodies. Behavior of cycle which is being specifief to be an interface would be appearing like this:
Java Code:
interface Bicycle {

    //  wheel revolutions per minute
    void changeCadence(int newValue);

    void changeGear(int newValue);

    void speedUp(int increment);

    void applyBrakes(int decrement);
For implementation of this interface, your class name will change (to some specified bicycle brand, like, ACMEBicycle), & you will be using the “implements” keywords, in class declaration:
Java Code:
class ACMEBicycle implements Bicycle {

    // remainder of this class 
    // implemented as before
An interface implementation permits class to be much more formal regarding behavior it provides. A contract is formed by the interface b/w outside world & class, and compiler enforces this contract at building time. For interface implementation by the class, defined methods by interface shall be appearing in their source code, before successful compilation of class.

Submit "What Is an Interface?" to Facebook Submit "What Is an Interface?" to Digg Submit "What Is an Interface?" to Submit "What Is an Interface?" to StumbleUpon Submit "What Is an Interface?" to Google