.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> C# >> Post New Question Subscribe to Interview Questions

What's the difference between an interface and abstract class?

Posted By :iswarya     Posted Date :November 21, 2011    Points :40   Category :C# 
(1)In the interface all methods must be abstract.
(2)In the abstract class some methods can be concrete.

You can also find related Interview Question to What''s the difference between an interface and abstract class?  below: 

What is the difference between interface and abstract class ?

  
a class may inherit several interfaces, a class may inherit only one abstract class (More...)

What is difference between abstract class and an interface?

  
An Abstract class is a class with some common/certain implementations and defines abstraction for other services which are implemented in its concrete sub classes, whereas interface only have method declaration with zero implementations. An abstract class and Interface both have method only but not have body of method. The difference between Abstract class and An Interface is that if u call Abstract class then u have to call all method of that particular Abstract class but if u call an Interface then it is not necessary that u call all method of that particular interface. An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.

An interface is not a class. It is an entity that is defined by the word Interface. An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. As one of the similarities to Abstract class, it is a contract that is used to define hierarchies for all subclasses or it defines specific set of methods and their arguments. The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn't support multiple inheritance, interfaces are used to implement multiple inheritance.


Shashi Ray (More...)

What's the difference between an interface and abstract class?

  
In an interface class, all methods must be abstract. In an abstract class some methods can be concrete. In an interface class, no accessibility modifiers are allowed, which is ok in an abstract class. (More...)

What's the difference between an interface and abstract class?

  
Abstract Class:

A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.

Interface:

Interfaces like classes define a set of properties methods and events. But unlike classes interfaces do not provide implementation. They are implemented by classes and defined as separate entities from classes (More...)

Difference between Interface and abstract class

  
When we need the subclasses to must implement all the methods of base class the then we Interface.
Abstract class can also contain no-abstract methods (More...)

What is difference between interface inheritance and class inheritance?

  
We can only inherit from one class but multiple interfaces. In addition, an interface does not contain any implementation it just contains a series of signatures. (More...)

what is the difference between a class and a interface?

  
You can instantiate a class but you cannot instantiate an interface,you can only offer the funtionality of that interface not the implementation. (More...)

What is the difference between abstract class and interfaces?

  
1) Concrete methods are applicable to abstract class only, interface cannot use them.

2)Abstract class uses inheritance while interface does not use inheritance. (More...)

What is an interface and what is an abstract class?

  
In an interface class, all methods are abstract without implementation whereas in an abstract class, some methods we can define concrete.

In interface, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers. Interface and abstract class are basically a set of rules which you have to follow in case you are using/inheriting them. (More...)

What is the difference between Abstract and Interface.

  
Interface is not a class. An interface can only contain the method definition without the body.

On the other-hand, an abstract class is a class that contains the method definition and may or may not contain the method body.
It acts as a base class can be inherited from other child class.

One class can inherit only one abstract class at a given time where is it can implement one or more interface. (More...)

What is the difference between a Struct and a Class?

  
The struct type is suitable for representing lightweight objects such as Point, Rectangle, and Color. Although it is possible to represent a point as a class, a struct is more efficient in some scenarios. For example, if you declare an array of 1000 Point objects, you will allocate additional memory for referencing each object. In this case, the struct is less expensive.

When you create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the new operator. If you do not use new, the fields will remain unassigned and the object cannot be used until all of the fields are initialized.

It is an error to declare a default (parameterless) constructor for a struct. A default constructor is always provided to initialize the struct members to their default values.

It is an error to initialize an instance field in a struct.

There is no inheritance for structs as there is for classes. A struct cannot inherit from another struct or class, and it cannot be the base of a class. Structs, however, inherit from the base class Object. A struct can implement interfaces, and it does that exactly as classes do.

A struct is a value type, while a class is a reference type. (More...)

When do you have to declare a class as abstract?

  
1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
2. When at least one of the methods in the class is abstract. (More...)

What's the difference between the Debug class and Trace class?

  
Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds. (More...)

What is the difference between a struct and a class in C#?

  
Strut is a value type.
Class is a reference type.

Class comes in OOPS. But strut does not come in OOPS.
Strut uses less memory than class at run time. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend