OOP Interfaces Demo in Java - Part 5

The concept of an Interface in Java is designed to replace the functionality of multiple inheritance. C++, another object oriented programming language, supports multiple inheritance, Java does not. While Interfaces are very common in Java programming, some programmers avoid them. This example of OOP Interfaces Demo in Java provides an introduction to creating, implementing, and applying interfaces in the Java programming language. We illustrate OOP concepts with functional java source code and accompanying documentation.

This is the 5th and final part of a tutorial on Interfaces in Java.

Synopsis

In this section of the tutorial we create a basic class that uses our interface. The class, Car, models a (very) simple automobile. As the purpose of this class is to demonstrate the useage of the interface, the class is not intended to be purposeful by any means.

Note the reference to the interface in the class definition:

public class Car extends BaseClass implements InterfaceDemo

The Java keyword implements will obligate our class to provide methods that conform to all the signatures that we included in the interface definition

Part 5

package InterfaceDemo;

/**
 *
 * @author nicomp
 *
 * This class models a car on an assembly line.
 * It implements the InterfaceDemo interface.
 */
public class Car extends BaseClass implements InterfaceDemo {

        public boolean Build() {
            boolean status = false;
//          We don't know how to build a car, yet.
//          However, we can still implement the interface to a limited extent.

//          The code that is specific to building a car would go here.
            System.out.println("\nHello from Car.Build()");
            return status;
        }
}

More by this Author


Comments 1 comment

psychicdog.net profile image

psychicdog.net 5 years ago

Poor cars - they get used so often as example objects in OOP but no one ever builds them!

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working