Tell me the scenario,Where we can use interfaces or
Abstract class.And What is the difference between
interfaces and abstract class?

Answers were Sorted based on User's Feedback



Tell me the scenario,Where we can use interfaces or Abstract class.And What is the difference betw..

Answer / 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

Tell me the scenario,Where we can use interfaces or Abstract class.And What is the difference betw..

Answer / bhavani

The whole reason you have a special Interface type-category
in addition to abstract base classes in C#/Java is because
C#/Java do not support multiple inheritance.

C++ supports multiple inheritance, and so a special type
isn't needed. An abstract base class with no non-abstract
methods is functionally equivalent to a C#/Java interface.

Is This Answer Correct ?    3 Yes 2 No

Tell me the scenario,Where we can use interfaces or Abstract class.And What is the difference betw..

Answer / vishal

Abstract Class encapsulates shared(common) behavior and
define place holder for all subclasses
- Define shared behavior
- Can have implementation code
- Can not be instantiated
- A class can be inherited from single abstract
class—Unless language supports Multiple inheritance.
- Provide both abstract and concrete menthods
- Strict IS-A relationship.
Interface: If there is no shared behavior –each subclass
must implement all method defines in a base class this is
called as Interface
- Defines Behavior. It is a cntract and its subclass
must implement it.
- Can not be instantiated
- A class can implemet mutiple interfaces
- Provide only abstract methods
- Not a strict IS-A relationship

Is This Answer Correct ?    0 Yes 0 No

Tell me the scenario,Where we can use interfaces or Abstract class.And What is the difference betw..

Answer / aaa

there is not interface and abstrcat keyword in C++.
but in CLR and Java

Is This Answer Correct ?    6 Yes 15 No

Tell me the scenario,Where we can use interfaces or Abstract class.And What is the difference betw..

Answer / seshu

abstract class contains function prototypes and function
definations also
but interface ccontains onlu function prototypes which are
used in deriving object declarations

Is This Answer Correct ?    8 Yes 18 No

Post New Answer

More OOPS Interview Questions

define oops concept with example

1 Answers   Cap Gemini,


Write a program to compute for numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student's first name, then one space, then ten quiz scores all on one line. The quiz scores are in whole number and are separated by one space. Your program will take it input from this file and sends it output to a second file. The data in the output file will be exactly the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student's ten quiz scores. Use at least one function that has file streams as all or some of its arguments.

0 Answers  


in the following, A D B G E C F Each of the seven digits from 0,1,2,3,4,5,6,7,8,9 is: a)Represented by a different letter in abov fig: b)Positioned in the fig abov so tht A*B*C,B*G*E,D*E*F are equal. wch does g represents? C

1 Answers   IonIdea,


What is R T T I ?

6 Answers   Ness Technologies,


How does polymorphism work?

0 Answers  






What does I oop mean?

0 Answers  


What is oops concept with example?

0 Answers  


Tell me the scenario,Where we can use interfaces or Abstract class.And What is the difference between interfaces and abstract class?

5 Answers  


what is the advantage in software? what is the difference between the software developer and Engineer

1 Answers  


create a c++ program that will ask 10 numbers and display their sum using array.

1 Answers  


What is late bound function call and early bound function call? Differentiate.

2 Answers   Ness Technologies,


write a function that takes an integer array as an input and finds the largest number in the array. You can not sort array or use any API or searching needs?

2 Answers   IBMS, Zycus Infotech,


Categories