ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming»
  • Programming Languages

Java Programming with Eclipse-The Best Beginners Tutorial:Abstract class and interface difference

Updated on June 9, 2013

Abstract Class and Interface

Abstract class is very interesting feature in java. It allows you to create skeleton class which contain function definition and description. It can be better understood by the example.

Here you will see that AbstractClass contains full set function with description. This class also contain the get function with function definition. As it does not contain function description so we have to declare it Abstract. Any class that will inherit this have to describe the get function, otherwise it will also be declared abstract.

One point also is that if we write abstract keyword before any function, then other class function can’t override that function. If any class write abstract before it, then other can’t extend it.

Interface

Interface in java is the collection of function definition. In eclipse you go in eclipse file>new>interface.

Create interface with the name employeeinterface.Here you can see that we have only function definition called showText.Now any class can implement it and provide the description of it.Interfaces are very important for long projects as they support reusability.

Interface In Java is similar to abstract class but it has some difference
Interface In Java is similar to abstract class but it has some difference | Source

You can also declare variable in these function. If you see the above program you will notice it, but these variable by default will be constant variable.

We implement interface but extend the other class
We implement interface but extend the other class | Source

Write the above program. Any class that wants to have this functions has to
implements this employeeinterface.That class has to provide implementation of all function.

You can also declare variable in these function. If you see the above program you will notice it, but these variable by default will be constant variable.

Difference between Abstract class and interface

Abstract class can contain function definition and description but interface can only contain function. Abstract class are extended by inherited class but interface are implemented by class.

Variable declared in interface by default is final.Final variable are the variable that can't be changed but variable declared in abstract are not final by default.

Abstract Class And Interface Difference in video

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.