CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS MICROSOFT C# DETAILS
Question :
What is an abstract class?


Category C# Interview Questions
Rating (5.0) By 6 users
Added on 7/28/2006
Views 4137
Rate it!
Answers:

The abstract modifier can be used with classes, methods, properties, indexers, and events.

Use the abstract modifier in a class declaration to indicate that a class is intended only to be a base class of other classes.

Abstract classes have the following features:

An abstract class cannot be instantiated.
An abstract class may contain abstract methods and accessors.
It is not possible to modify an abstract class with the sealed modifier, which means that the class cannot be inherited.
A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.
Use the abstract modifier in a method or property declaration to indicate that the method or property does not contain implementation.

Abstract methods have the following features:

An abstract method is implicitly a virtual method.
Abstract method declarations are only permitted in abstract classes.
Because an abstract method declaration provides no actual implementation, there is no method body; the method declaration simply ends with a semicolon and there are no braces ({ }) following the signature. For example:
public abstract void MyMethod();



abstract class is a prototype of a class. it is used to provide partial
class implementation. abstract class contain abstract method which can be implemented by derived class.
some rules for abstract class are following-:
1) an object of an abstract class can never be created.
2)you can not declare an abstract method outside the abstract class.
3)can not be declared sealed.



 Posted by: ritesh    

Contact ritesh  Contact ritesh

Abstract is a keyword.

Whenever a class is not providing full information then that class is called as Abstract Class.

A method without body is called as Abstract Class.

When a class contains atleast one abstract method also, then that class must be declared as Abstract Class.

Abstract method is also called as Rules.

Abstract method must be overrided in the derived classes.

Abstract class provides a set of rules(abstract methods) which must be followed (overrided) in the derived classes.

Abstract classes are not instantiatable(ie. object cannot be created) but a reference can be created.
Ex:- Test t = new Test; //object
Area a; // reference

Object contains its own memory but reference does not contain own memory.

Reference works based on child class memory.





 Posted by: Aaber Osmani    

Contact Aaber Osmani  Contact Aaber Osmani

The abstract modifier can be used with classes, methods, properties, indexers, and events.
An abstract class cannot be instantiated.
An abstract class may contain abstract methods and accessors.
Abstract class is a prototype of a class. it is used to provide partial class implementation. abstract class contain abstract method which can be implemented by derived class.



 Posted by: piyush    

Contact piyush  Contact piyush

abstract class is similar to classes in many cases.

but it only declares properties and members and leaves the implementation on the child classes.

except this these classes have following features :

1-you cannot instantiate abstract classes.
2-you can inherit any child class only form one abstract class.
this is a wrong syntax :
[child class:abstract1:abstract2 ]
this is correct syntax :
[ child class:abstract1]

3- abstract methods can be declared only in abstract classes.



 Posted by: ritesh    

Contact ritesh  Contact ritesh

abstract class is a special base class that consist of abstract class member.

All the class member derived directly from abstract class must implement all the abstract function and properties.



 Posted by: venkatesan    

Contact venkatesan  Contact venkatesan

"abstract" is a keyword to declare the abstract classes. Below is the syntax
abstract Class A
{

}

In abstract class declaration is provided but not Implementation

If one or more methods declared as abstract then the class should classify as "abstract' and you cannot insantiate the abstract classes. if a class which is inherting the abstract class then it should override all the abstract methods of base class in derived class. If the Inherted class is not overriding the abstract methods in derived class then the that class should be classify as abstract

A abstract method will have all the features of Concrete class like constructos and it will have abstract methods which concrete class doesnot

abstract Class CParent
{
Public abstract Void Foo()
{
console.writeline("Foo in Parentclass");
}
}

Class CChild:CParent
{

public override void Foo()
{
Console.WriteLine("Foo in child class");
}
}



 Posted by: Nageswara Rao    

Contact Nageswara Rao  Contact Nageswara Rao


Abstract class is a special kind of class which cannot be instantiated. Instantiated means we can not create any object at that class. We will create only abstract methods and concrete methods.
Abstract methods can not have body where as concrete method has body that means implementation.
We can call these methods in another class and implement the code what ever we want.

E.g.:-
Abstract class shape
{
Abstract void sides ();
}
Class line: shape
{
Public void sides ()
{
Console. Write (?one side?);
}}
Class triangle: shape
{
Public void sides ()
{
Console. Write (?three sides?);
}}
Class square: shape
{
Public void sides ()
{
Console. Write (?four sides?);
}}
Class side
{
Static void main ()
{
line l = new line ();
triangle t = new triangle ();
square s = new square();
l.sides ();
t.sides ();
s.sides ();
}
}



 Posted by: sravan kumar    

Contact sravan kumar  Contact sravan kumar

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,an Abstract class superclass is a conceptual class does not exist in the real word, but acts as a base from which other class inherit perporties behavior



 Posted by: ramani    

Contact ramani  Contact ramani


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What does the keyword virtual mean in the method definition?

View Answer
How's method overriding different from overloading?

View Answer
What's the top .NET class that everything is derived from?

View Answer
Describe the accessibility modifier protected internal.

View Answer
Are private class-level variables inherited?

View Answer
When you inherit a protected class-level variable? Who is it available to?

View Answer
Does C# support multiple inheritance?

View Answer
How do you inherit from a class in C#?

View Answer
What's the implicit name of the parameter that gets passed into the class' set method?

View Answer
Is it mandatory to implement all the methods which are there in abstract class if we inherit that abstract class..?

View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C# Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/9102/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.69