constuctor
what will happen if i use constructor in abstract class in asp.net
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.
VulpesPosted Nov 8, 2012, 6:15 AM
There's nothing wrong with your example which is a good one :)
Akash RoyPosted Nov 8, 2012, 2:13 AM
VulpesPosted Nov 7, 2012, 8:44 AM
If you change A's constructor from protected to public in Akash's example and try to instantiate A using this line:
A a = new A("Hello");
then you'll get the following compiler error:
Akash RoyPosted Nov 7, 2012, 7:49 AM
That way you can have classes that inherit from that class call the base constructor.
public abstract class A{
private string data;
protected A(string myString){
data = myString;
}
}
public class B : A {
B(string myString) : base(mystring){}
}
accept this answer if it solves your issue..
Akash