Hi All,
I know all the difference and similaerty of abstract class and Interface,
but i want to know that what are the senerio in which i should use the abstract class
and what are the senerio in which i have to use an Interface.
Hi All,
I know all the difference and similaerty of abstract class and Interface,
but i want to know that what are the senerio in which i should use the abstract class
and what are the senerio in which i have to use an Interface.
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.
Amit ChoudharyPosted Nov 25, 2009, 7:35 AM
The main difference is you can not multiply inherit the abstract class....
Nilanka DharmadasaPosted Nov 24, 2009, 8:42 AM
Let's say you write an abstarct class A and an interface B.
Then you want to inherit class C from A or B.
If you inherit C from A, then you cannot inherit C from any other class.
If you inherit C from B, then you can inherit from another class too.
But, in B, you can have only method definitions. You cannot write code inside the interface. Only the signatures of the methods and constants.
In A, you can have some coding too. If you have some common code, then you can write them in a abstract class and it will be inherited to the child classes. But this is not possible in interface.
Hope now it's clear for you. Now you can decide on how to select it.
If you find my answer useful, do not forget to mark Do you like this answer checkbox.
arvind haritusPosted Nov 24, 2009, 1:59 AM
What you want to say i am not getting can you please tell me in detail.
One more thing, Inheritance is not a question because whatever we create(either interface or abstract class) if we want to inherit these from other class or interface the situation is same in both the cases either it is interface or abstract class...
-Arvind
Amit ChoudharyPosted Nov 24, 2009, 1:41 AM
If you want to use the class as functionally overloaded and can be inherited with multiple class then make it interface and if you want only to overload the functionality not for multiple inheritance you can use Abstract classes......
Hope you get it.... its by my experience .....and dont forget to mark the answer if it helps.....:)