answersLogoWhite

0


Best Answer

Abstract classes and Interfaces are both examples of contracts with no default implementation. Interfaces are more readily interchangeable between applications (because they can be interpreted as jump tables). Because of this COM in Windows makes heavy usage of interfaces with several master ones being the source of all functionality (e.g., IUnknown).

If a programmer wanted to define a type of thing (e.g., MusicalInstrument), that had certain abilities (e.g. Play) without defining how a MusicalInstrument plays... This could be done with an Interface or an Abstract class.

If the programmer wanted to provide some base functionality to whomever was going to implement this functionality (e.g., Vloume, Output Stream) then this would be more appropriate for an Abstract class.

Abstract classes can even build on interfaces:

public interface IMusicalInstrument

{ void Play(); }

public abstract class MusicalInstrument:IMusicalInstrument

{ private int vol = 10;

public virtual SetVolume(int newVol){vol = newVol;}

public abstract void Play(); }

public class Horn:MusicalInstrument

{ public override void Play(){//* Play something *//} }

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can anyone 1 pls give a real time example and usage of abstract class and interface in c sharp?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is difference between abstract class and interface in core java give brief answer with example?

Differences:Abstract class can also contain method definitions but an interface can contain only declarationsAll variables in an interface are by default public static and final whereas in Abstract class it is notAn interface can be considered as a pure abstract class that contains no method implementations and contains only declarations.


What is similarities between Abstract Class and Interface?

If a class has one abstract method ,the class has to be an abstract class.Methods can be implemented in abstract class.Whereas a interface is like a abstract class...the only difference being that the methods are never implemented in Interface.


What is an interface class and what is an abstract class?

The term interface class does not exist in C#. If this is a term describing a class being an interface to other component (human, subsystems, etc), it is very application specific. The designer of that application should know the abstraction.However, C# does have another type called interface. An interface is NOT a class. An interface defines the intention of some behaviors that classes may be extended it and provides the implementation. The intention, is nothing but method signatures, which defines the return data type, the method name, and any method arguments and associated data type. The implementation is the code of the method. Interface is used for separating the concern of design and implementation.Abstract class is a class with abstract keyword. It can be just like a class without that keyword (then, why it is an abstract class?). But it may have some methods or properties defined as abstract. These abstract methods, like the method signatures of an interface, defines the intention.The subclasses of such an abstract class would need to implement those abstract methods (providing the code).There are more common, differences between interfaces and abstract classes, please see answer(s) of those related questions in C# category.


What is the difference between an interface and an abstract class?

We can't instantiate both interfaces and abstract classes.The only one difference between them is that an interface can't contain concrete(fully defined) methods where as an abstract class may contain them.An abstract class not necessarily contain abstract methods. we can make a class as abstract class even it does not has any abstract methods.When there is a need to write both abstract and concrete methods in a single unit we have to use an abstract class instead of an interface since an interface cant contain concrete methods.All the fields(or properties) of an interface are by default 'static final' even when you don't mention explicitly. And all methods are 'public abstract'.But in an abstract class we can have any type of fields and methods.


Abstract class vs interface?

Comparison between an Abstract Class and an Interface:While an abstract class can define both abstract and non-abstract methods, an interface can have only abstract methods. Another way interfaces differ from abstract classes is that interfaces have very little flexibility in how the methods and variables defined in the interface are declared. These rules are strict:

Related questions

What is difference between abstract class and interface in core java give brief answer with example?

Differences:Abstract class can also contain method definitions but an interface can contain only declarationsAll variables in an interface are by default public static and final whereas in Abstract class it is notAn interface can be considered as a pure abstract class that contains no method implementations and contains only declarations.


What is similarities between Abstract Class and Interface?

If a class has one abstract method ,the class has to be an abstract class.Methods can be implemented in abstract class.Whereas a interface is like a abstract class...the only difference being that the methods are never implemented in Interface.


What is an interface class and what is an abstract class?

The term interface class does not exist in C#. If this is a term describing a class being an interface to other component (human, subsystems, etc), it is very application specific. The designer of that application should know the abstraction.However, C# does have another type called interface. An interface is NOT a class. An interface defines the intention of some behaviors that classes may be extended it and provides the implementation. The intention, is nothing but method signatures, which defines the return data type, the method name, and any method arguments and associated data type. The implementation is the code of the method. Interface is used for separating the concern of design and implementation.Abstract class is a class with abstract keyword. It can be just like a class without that keyword (then, why it is an abstract class?). But it may have some methods or properties defined as abstract. These abstract methods, like the method signatures of an interface, defines the intention.The subclasses of such an abstract class would need to implement those abstract methods (providing the code).There are more common, differences between interfaces and abstract classes, please see answer(s) of those related questions in C# category.


What is the difference between an interface and an abstract class?

We can't instantiate both interfaces and abstract classes.The only one difference between them is that an interface can't contain concrete(fully defined) methods where as an abstract class may contain them.An abstract class not necessarily contain abstract methods. we can make a class as abstract class even it does not has any abstract methods.When there is a need to write both abstract and concrete methods in a single unit we have to use an abstract class instead of an interface since an interface cant contain concrete methods.All the fields(or properties) of an interface are by default 'static final' even when you don't mention explicitly. And all methods are 'public abstract'.But in an abstract class we can have any type of fields and methods.


Real time example for interface vs abstract class in java?

w.frnds........ I am just trying to an example of abstract class and interface class in real life . As these two ["interface class" is not a term in Java programming - just "interface"] classes [sic] are a concept of objest orientation so easy we can easily compare thhese with our real life . Suppose we have an abstract class called clark and an abstract method behabour of this abstract class ,which has no definition in abstract class. two other class security and receptionist inherits these clark class. So in thses two derived class there must has to be a defonation of behabour method,which depends on the derived class which types of behabour they will show........ So that is a real life example of Abstract class .Interface is also same as abstract class only the difference is it can't contain any implementation of any method in base class or super class. I think this is a sufficient example to understand abstract class and interface. [No, it is not sufficient.] If u have any doubt then u can contact me with this email id-rkmahanta26@gmail.com [Interfaces support multiple inheritance; classes do not. Interfaces contain only public members; classes do not have to. Interfaces do not have superclasses, except the implicit 'Object' supertype; they have superinterfaces. Nested interfaces are always static, never inner, unlike classes which can be inner classes. "u" is not an English pronoun. Use the tutorial and the JLS to understand interfaces and abstract classes, not this garbage answer.]


Abstract class vs interface?

Comparison between an Abstract Class and an Interface:While an abstract class can define both abstract and non-abstract methods, an interface can have only abstract methods. Another way interfaces differ from abstract classes is that interfaces have very little flexibility in how the methods and variables defined in the interface are declared. These rules are strict:


What are the differences between an abstract class and an interface in java?

They are very different. An abstract class is a class that represents an abstract concept (google define "abstract" if you're unsure) such as 'Thoughts' or 'BankAccount'. When a class is defined as abstract it cannot be used (directly) to create an object. Abstract classes are used as super-classes so that all of their subclasses inherit all methods. Interfaces can be thought of as contracts with all of their implementing classes. They simply require all implementing classes to have methods with the same signature as that defined in the interface, but such methods can behave as appropriate. Hope that helps :)


What is difference between interface and abstract class?

All the methods declared inside an Interface are abstract. Where as abstract class must have at least one abstract method and others may be concrete or abstract. In Interface we need not use the keyword abstract for the methods.


Difference between interface and abstract class on uml?

In general, the differences are that interface has(1) no fields and(2) no implementation of methodsbut in UML interface may have features (fields), so the difference left is that interface in UML has no implemented methods while abstract class by definition is partially implemented class.


Why instance in abstract or interface?

we can make object of interface but in abstract we can not make object of it interface ab= new Classs(): in interface we maintain multiple inhetence by use of obj of interface we if inherit two class have same fun then we give the name of that interface and call the pertucular that fun interface ab= new class() ab.add(); but in Astract Class we cannot make object of it only class class wich inherit it can make object class ab2= new Class(); and by obj we call function of drived class ob2.add();


What is the major difference between an Interface and a Class?

An interface can only have abstract methods or constants in it. A class can have both that and everything else in Java.


When an interface method is implemented in a class it must be declared as?

Abstract type