What is use of Interface
Abstract class has abstract method and not abstract method .then what is use of 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.
Rafnas T PPosted Mar 20, 2017, 6:45 AM
Rathrola Prem KumarPosted Mar 20, 2017, 4:04 AM
Interfaces are better suited to situations in which your applications require many possibly unrelated object types to provide certain functionality.
Interfaces are more flexible than base classes because you can define a single implementation that can implement multiple interfaces.
Interfaces are better in situations in which you do not have to inherit implementation from a base class.
Interfaces are useful when you cannot use class inheritance. For example, structures cannot inherit from classes, but they can implement interfaces.
Vincent Maverick DuranoPosted May 21, 2015, 9:18 AM
Sure. Here's a simple implementation of that. First define your interface with the Sum, Difference, Multiply and Divide methods like:
public interface ICalulator
{
T Sum(T a, T b);
T Difference(T a, T b);
T Multiply(T a, T b);
T Divide(T a, T b);
}
the "T" there is the type that the iterface will be using to do the operations for example int, decimal or whatever.
Now you can then create a concrete class than implement the interface:
public class Int32Calculator : ICalulator
{
public Int32 Sum(Int32 a, Int32 b) {
return a + b;
}
public Int32 Difference(Int32 a, Int32 b) {
return a - b;
}
public Int32 Multiply(Int32 a, Int32 b) {
return a * b;
}
public Int32 Divide(Int32 a, Int32 b) {
return a / b;
}
}
and use it like this:
Int32Calculator calcu = new Int32Calculator();
int sum = calcu.Sum(5, 8);
int sub = calcu.Difference(5,5);
int mul = calcu.Multiply(2,3);
int div = calcu.Divide(10,2);
Lalit RaghavPosted May 21, 2015, 6:18 AM
Chplaya - Tải Play Store FreePosted May 6, 2015, 6:46 AM
Vincent Maverick DuranoPosted May 5, 2015, 7:36 AM
Lalit RaghavPosted May 5, 2015, 1:30 AM
Dipankar BiswasPosted May 5, 2015, 1:19 AM
check here...
http://www.c-sharpcorner.com/UploadFile/sekarbalag/interface-best-example-in-csharp/http://www.c-sharpcorner.com/UploadFile/sekarbalag/interface-best-example-in-csharp/
Rajeesh MenothPosted May 4, 2015, 11:55 PM
Abstract Class:
-Abstract class provides a set of rules to implement next class
-Rules will be provided through abstract methods
-Abstract method does not contain any definition
-While inheriting abstract class all abstract methods must be override
-If a class contains at least one abstract method then it must be declared as an "Abstract Class"
-Abstract classes cannot be instantiated (i.e. we cannot create objects), but a reference can be created
-Reference depends on child class object's memory
-Abstract classes are also called as "Partial abstract classes"
-Partial abstract class may contain functions with body and functions without body
-If a class contains all functions without body then it is called as "Fully Abstract Class" (Interface)
Interface:
-If a class contains all abstract methods then that class is known as "Interface"
-Interfaces support like multiple inheritance
-In interface all methods r public abstract by default
-Interfaces r implementable
-Interfaces can be instantiated, but a reference cannot be created
MahaPosted May 4, 2015, 2:58 PM
class A
{
}
class B:A (B inherits from A which is allowed in C#)
{
}
class C : A, B (C inherits from A & B. This is multiple inheritances which is not allowed in C#)
{
}
Gopi ChandPosted May 4, 2015, 2:46 PM
Get the detail knowledge about use of interface
http://www.c-sharpcorner.com/UploadFile/9a9e6f/interface-keyword-in-java/
Vincent Maverick DuranoPosted May 4, 2015, 1:59 PM
Your question has been asked many times before so I would suggest you to do a bit of search at google to get more information and examples of interfaces.
Akhil GargPosted May 4, 2015, 1:45 PM
Interface supports multiple inheritance