what is difference between abstract class and interface with real time example(with simple project)
Loading
what is difference between abstract class and interface with real time example(with simple project)
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sachin SinghPosted Jan 24, 2022, 7:19 AM
An interface has only abstract methods (method without body) but an abstract class can have both abstract as well as non abstract methods (methods with body), so it can also support access modifiers (private,internal etc) but interface has by default public methods only.
so, it is a common practice that whenever you have to create contract (force child class to implement and use same naming conventations) we use interface.
Another benefit of interface is to achieve loose coupling between two projects or classes. we use interface instead of concrete objects which also hides the real implementions from caller class.
so, caller doesn't know which implementation out of the given two implementions, _DepartmentBL pointing to, and will be resolved at run time using dependency injection.
Muhammad Imran AnsariPosted Jan 24, 2022, 6:19 AM