What's the difference between interface and abstract class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's the difference between interface and abstract class?

6th Aug 2018, 5:04 PM
Girish L V
Girish L V - avatar
7 Answers
+ 2
just to add, when you just want to hide everything from user; you use interface... best example is ATM machine main window.. based on type of ATM card you insert, it creates object of different banks and ask you logical questions based on different banks in different sequence.. same ATM asks different questions if you insert SBI or icicic card... here main class is interface and no method should be implemented here... this is my thought ... I am just giving you example which best suits interface based on my knowledge...
6th Aug 2018, 5:44 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Girish L V in c++, abstract class must have atleast one pure virtual method which will be implemented in other class... Abstract class may have other method implemented in same class rather than making it pure virtual.. for interface, there is no method implemented in class.. all methods should be implemented in other classes and one should make all methods as pure virtual.. I am unaware about java...
6th Aug 2018, 5:16 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
it depends on your requirement... class Bank() { public: int SetMinBalanceReq() = 0; }; class Bank1() { public: int SetMinBalanceReq() = 0; void SetAccDetail() { //your code } }; refer above and observe that bank class is interface as it has no implemented method... bank1 is abstract class as it has one pure virtual method along with implemented method minbalance is to be implemented in different class based on account type...
6th Aug 2018, 5:33 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
thank you so much
6th Aug 2018, 5:39 PM
Girish L V
Girish L V - avatar
+ 1
happy to help... feel free to ask if you have question... will try best to let you know...
6th Aug 2018, 5:40 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
do you know any example for both interface and abstract class
6th Aug 2018, 5:20 PM
Girish L V
Girish L V - avatar
0
are you from?
6th Aug 2018, 5:42 PM
Girish L V
Girish L V - avatar