When we will use an Interface and Abstract class?

Answer Posted / mohd shakir

I think if you have basics knowledge of any OO language then you should be aware of basic definition of Interface and Abstract class.

Here I am going to explain when to use Interface and when to use Abstract class.

Abstract class:-> If you have a common functionality that is used by its subclasses then put that method in super abstract class(now you need not to define that common method in every subclass again and again) This is what you can't do with Interface(because all the methods are by default abstract).

Interface:-> If you don't have the scenario as I discussed above(in abstract class)then choose Interface.And you can also achieve multiple inheritance using Interface that is not possible in case of Abstract class.

Is This Answer Correct ?    21 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which of the classes will have more memory allocated?

746


Explain methods specific to list interface?

751


What is int lol?

865


What best practices should you follow while writing multithreaded code in java?

778


How do you define a singleton class?

789


What is a qualifier in a sentence?

759


Explain throw keyword in java?

829


What is difference between equal and == in java?

723


How to create a custom exception?

754


Differentiate between array list and vector in java.

874


What are the various access specifiers in java?

758


What are inner classes or non static nested classes in java?

933


What is an escape character in java?

781


What are different types of multitasking?

734


What is class forname?

737