Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

You are free to use abstract class or interface. Tell me a scenario where you would use interface or abstract class? How would you decide?

user-image
Question added by Firoz Ahmad , Software Engineer , Tata Consultancy Service Limited
Date Posted: 2017/05/09

Interface and abstract class are made for different purposes. For the simple example, suppose you are implementing play behaviour in the Football player and cricket player. Then first you will make Class Player, then make FootballPlayer extending Player, similarly CricketPlayer.

But if you are implementing play behaviour in Human and Animal then, for this scenario abstract class is not a good choice, you have to make an Interface EatableInterface which has eat method and Human and Animal class will implement that interface.

for other uses of the interface, you can learn about some design patterns, in design patterns interface is heavily used.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.