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
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 |
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 |
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 |
Answer / aaa
there is not interface and abstrcat keyword in C++.
but in CLR and Java
Is This Answer Correct ? | 6 Yes | 15 No |
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 |
write a C++ program for booking using constructor and destructor.
1. Strong name 2. how to prevent a class from being inherited 3. delegates 4. default modifier for interface 5. default modifier for class 6. base class for exception 7. diff bet trigger and view in sql 8. how to exchange values from one page to another page 9. can multiple catch block ll be executed at same time 10. can u store different data types in an array & array list 11. when we ll use trigger 12. try,catch,finally usage
hi all..i want to know oops concepts clearly can any1 explain??
different types of castings
Why is polymorphism used?
Write a macro for swapping integers
what is the usage of clas templates
Program to check whether a word is the first word of the sentence.
Name an advantage of linked list over array?
Question: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date.
what is a ststic variable and stiticfunction briefly explain with exmple and in which case we use
Question In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Question Submitted By :: Sunil Kumar I also faced this Question!! Rank Answer Posted By Re: In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Answer # 1 use copy constructors 0 Shanthila There is something to be taken care in destructor, in copy constructor, suppose the memory is assigned to the embedded member object pointer with the parameter passed value, but if some other objects of different class also are pointing to this memory, then if some one deletes the object then this class member pointer object will become dangling, or if the object is not deleted properly then there will be memory leak. Please suggest the design change required to handle or avoid this situation