difference between concerte class vs abstract class

Posted by Raja123 under Interview Questions on 9/6/2010 | Points: 10 | Views : 8813 | Status : [Member] | Replies : 5
what is difference between concerte class vs abstract class ?




Responses

Posted by: Peermohamedmydeen on: 9/6/2010 [Member] Bronze | Points: 25

Up
0
Down
Concrete class
1. we can create instance as well as we can inherit.
2. No method should be abstract.
3. In application class hierarchy, concrete class need not be in the first level.

Abstract class

1. We can not instantiate but we can inherit.
2. At least one method should be abstract.
3.In application class hierarchy, abstract class can be at the first level.

Thanks
PMM :)

Raja123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja123 on: 9/6/2010 [Member] Starter | Points: 25

Up
0
Down
Thanks you very much... if u provide with some code snippet for this . please this will useful for m and other visitor also.

Raja123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kishork80 on: 9/6/2010 [Member] Starter | Points: 25

Up
0
Down
Nice answer but the point is not correct.
2. At least one method should be abstract

We can have an abstract class without having any abstract method.
example.
abstract class clsAbstTest
{
public void DisplayTest(){Console.WriteLine("DisplayTest");}
}

Kindly check :)

kishor kumar

Raja123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Syedshakeer on: 9/6/2010 [Member] Starter | Points: 25

Up
0
Down
Hi,
Check the following lin for more details
http://www.programmersheaven.com/2/Les_CSharp_7_p1

Syed Shakeer Hussain

Raja123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sonalee2304 on: 9/8/2010 [Member] Starter | Points: 25

Up
0
Down
    abstract class absClass

{
public int AddTwoNumbers(int Num1, int Num2)
{ return Num1 + Num2; }

public abstract int MultiplyTwoNumbers(int Num1, int Num2);
}

//A Child Class of absClass
class absDerived : absClass
{
[STAThread]
static void Main(string[] args)
{
//You can create an instance of the derived class

absDerived calculate = new absDerived();
int added = calculate.AddTwoNumbers(10, 20);
int multiplied = calculate.MultiplyTwoNumbers(10, 20);
Console.WriteLine("Added : {0}, Multiplied : {1}", added, multiplied);
}

public override int MultiplyTwoNumbers(int Num1, int Num2)
{ return Num1 * Num2; }
}
}


An abstract class can contain either abstract methods or non abstract methods. Abstract members do not have any implementation in the abstract class, but the same has to be provided in its derived class.
An abstract class does not mean that it should contain abstract members. Even we can have an abstract class only with non abstract members.
An abstract class cannot be a sealed class.
Declaration of abstract methods are only allowed in abstract classes.
An abstract method cannot be private.
An abstract member cannot be static.
The access modifier of the abstract method should be same in both the abstract class and its derived class. If you declare an abstract method as protected, it should be protected in its derived class. Otherwise, the compiler will raise an error.An abstract method cannot have the modifier virtual. Because an abstract method is implicitly virtual.


Raja123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response