• Register
2 votes

Problem :

I am new to C# and I am currently preparing for my interview and I have below question.

When to use abstract class and interface in c# with real time example

Can somebody help me in finding correct answer for above question?

8 5 2
3,230 points

Please log in or register to answer this question.

1 Answer

2 votes

Solution :

This is the most frequently asked question in any C# interview. I am trying to answer it for you.

If you want to create the multiple versions of your component then you should create an abstract class. The abstract classes will provide the simple and very easy way to create different versions of your components. If you update your base class then all the inheriting classes will be  automatically updated with the change which you have made in base class. Interfaces are the blue prints and they cannot be changed once created. If for any reason a new version of the interface is required then in that case you must create the completely new interface.

If your functionality which you are creating is for a wide range of different objects then you should use the interface. The abstract classes can be used for the objects those are very closely related to each other and the interfaces should be used forgiving the common functionality for not related classes.

If you want to design the small functionality then you should use the interfaces. And if you want to  design the large functionality then you should use the abstract class.


8 4
5,680 points

Related questions

0 votes
1 answer 16 views
0 votes
1 answer 16 views
Problem I am newbie to C# I am confused by .Net Garbage Collection logic. When does GC free memory?
asked Oct 8, 2020 alexh 2.2k points
0 votes
1 answer 20 views
1 vote
1 answer 10 views
What are polymorphism and inheritance? Why And When To Use "Inheritance" and "Polymorphism"?
asked Oct 4, 2020 Sofi55 1.1k points
0 votes
1 answer 31 views
Problem: I am beginner to C#. Please find below my code for your help: public class MySoundManager : MonoBehaviour { public List<AudioSource> audioSounds = new List<AudioSource>(); public double minTime = 0.5; public static void playSound(AudioClip sourceSound, Vector3 objectPosition, int ... to create the object of a class or create a methods as the static one but I don&rsquo;t know how to do it.
asked Jul 22, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 3 views
Problem Hey, I want to know what abstract class and interface in C++. can you please help me to know about them?
asked 6 days ago chris jordan 2.1k points
0 votes
1 answer 11 views
How do you convert a numerical number to an Excel column name in C# without using automation getting the value directly from Excel.?
asked Aug 28, 2020 Aliza313 720 points
0 votes
1 answer 5 views
Problem: What is the difference between an interface and an abstract class in Java? When should we use interface and abstract class in Java? What is the difference between functional interface and abstract class? What is the difference between abstract class and interface with example?
asked Dec 3, 2020 Mashhoodch 5.6k points
0 votes
1 answer 12 views
Problem: Hi, I want to take multiple employee ids in one shot from the user and need to assign them to list .in asp.net, pls help me to sort it out. What I have tried. I have created a text box and tried with validator but it didn't worked out.
asked Sep 14, 2020 boris elin 620 points
1 vote
1 answer 29 views
What does CultureInfo.InvariantCulture mean? How to Convert String to DateTime?How to 2020-09-22 12:57:52,531Class string converted to DateTime ?
asked Sep 21, 2020 Aliza313 720 points