Home TechnologyDevices Subscribe to RSS

What Is The Difference Between Interface And Abstract Class And Interface And Multiple Inheritance?

Answer Question

1 Answer - Sort by: Date | Rating

    An abstract class is a class which you will never instantiate.  It is designed as the parent class from which other classes will inherit.  It contains a set of common features they will all have. It can contain concrete or abstract methods.

    An interface is similar to an abstract class but with one important difference.  ALL its methods are abstract. You state the methods that must be used, but do not include the body code for any of them.  EG in a geometry program you might have an interface which included an area method, a volume method and a findCentre method.  But as the code would be different for every geometrical shape, you leave the body empty.  When you use it, you MUST add the code for each empty method.

    In some langauges, such as Java, multiple inheritance is not allowed (thankfully, as it is a very complex way to work!).  But you can use more than one interface.  So it is a sort of way around the lack of multiple inheritance.
    0 1

    Drjohn 

    answered 3 years ago

      More

         
         

        Ask a Question via Twitter

        Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

        Blurtit Store

        Get T-shirts, hoodies, caps and more at the Blurtit store

        Blurtit International