Tell me the scenario,Where we can use interfaces or
Abstract class.And What is the difference between
interfaces and abstract class?
Answer Posted / kaushik thakrar
In relation to C# (not C++):
1. Interfaces are like abstract class where all member
functions as abstract but cannot have any data members,
constructors or destructors. Classes using interfaces are
forced to implement all the methods in the interface.
2. Does not implement any methods. ie only used as a
template for derived classes to use.
3. All members of interface are public. ie in Interface you
only have to state long Function(); but in a class you have
to state public abstract long Function();
4. A class can have multiple inheritence with an interface
but not a class.
5. Also structures in C# cannot inherit from other classes
of structures but can implement an interface allowing you
to implement more features to your class.
By using interfaces you are not making any assumptions
about the functionality. You want to make sure your classes
using the interfaces implement the functionality of all the
methods in your Interface.
With all above in mind you can probably find more uses for
an interface.
One example: You have many forms of communication like
FileIO or database or IPC. All these forms of communication
will need to features like Open and Close either a file or
a connection Read or write etc. You would then define an
interface with these features for your concrete classes.
You can then use the Interface as a base class pointer like
in C++ to access the derived class's functions.
| Is This Answer Correct ? | 10 Yes | 4 No |
Post New Answer View All Answers
Can enum be null?
what type of question are asked in thoughtworks pair programming round ?
write a program that takes input in digits and display the result in words from 1 to 1000
How many human genes are polymorphic?
c++ program to swap the objects of two different classes
What are the 3 principles of oop?
What does it mean when someone says I oop?
What are the benefits of polymorphism?
What is a function in oop?
write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.
What are the important components of cohesion?
Can bst contain duplicates?
Why oops is important?
just right the logic of it 1--> If few people are electing then every time ur candidate should win 2--> arrange books in box, if box carry weight == books weight then take another box..... find the no of box required.
How do you achieve polymorphism?