-6
    abstract class Animal
    {
        public string DefaultMessage { get; set; }

        public Animal()
        {
            Console.WriteLine("Animal Cstor called");
            DefaultMessage = "Default Speak";
        }
        public virtual void Speak()
        {
            Console.WriteLine(DefaultMessage);
        }
    }

    class Dog : Animal
    {
        public Dog()
            : base()//base() redundant.  There's an implicit call to base here.
        {
            Console.WriteLine("Dog cstror called");
        }
        public override void Speak()
        {
            Console.WriteLine("Custom Speak");//append new behavior
            base.Speak();//Re-use base behavior too
        }
    }

or else

class Animal
    {
        public string DefaultMessage { get; set; }

        public Animal()
        {
            Console.WriteLine("Animal Cstor called");
            DefaultMessage = "Default Speak";
        }
        public virtual void Speak()
        {
            Console.WriteLine(DefaultMessage);
        }
    }

    class Dog : Animal
    {
        public Dog()
            : base()//base() redundant.  There's an implicit call to base here.
        {
            Console.WriteLine("Dog cstror called");
        }
        public override void Speak()
        {
            Console.WriteLine("Custom Speak");//append new behavior
            base.Speak();//Re-use base behavior too
        }
    }
  1. what is the Difference between abstract class constructor and normal class constructor?
Sriram Sakthivel
  • 67,773
  • 7
  • 96
  • 172
  • 3
    What is the difference between doing your own homework and letting others do it for you? Do you even understand what you're asking? – CodeCaster Aug 03 '15 at 10:13
  • ## CodeCaster DUDE ## I DONE HOMEWORK FROM CHILDHOOD NOW I AM STANDING ASKING THIS QUESTION what is the Difference between abstract class constructor and normal class constructor? – COSNFUSING_CODER Aug 03 '15 at 10:18
  • 4
    Yes, I can read. The difference is that one is abstract and the other isn't. Why do you want to know? Is that actually what you want to know? What are you going to do with the answers? If this comes down to _"Explain what abstract means in C#"_, it's simply too broad. – CodeCaster Aug 03 '15 at 10:19
  • @yogesh There is a site called [GOOGLE](https://www.google.com) where you can ask this question and get a lot of tuterial to learn fundamentals of `C#` – too_cool Aug 03 '15 at 10:20
  • # CODE CASTER DUDE # WHATEVER abstract CLASS CTOR IS DOING SAME IS , I CAN DO FROM NORMAL CLASS, SO WHY ABSTRACT CLASS CTOR WE ARE USING? – COSNFUSING_CODER Aug 03 '15 at 10:22
  • 1
    @COSNFUSING_CODER Don't use capital letters! And if you've further questions, you should ask a new question and you also need to mark some of given answers to current question as the right one for you. – Matías Fidemraizer Aug 03 '15 at 10:24
  • 1
    Leave the caps out, please. In that comment you changed your question, it now is _"Why do we use abstract constructors?"_, which is a different question (and it has been answered before). See for example [Can an abstract class have a constructor?](http://stackoverflow.com/questions/260666/can-an-abstract-class-have-a-constructor). – CodeCaster Aug 03 '15 at 10:24
  • ##code caster ## my mistake, yes question should be like u say # thanks for comments. – COSNFUSING_CODER Aug 03 '15 at 10:33
  • A short side-node: to adress someone specific that commented on your question write @ (e.g. @CONFUSING_CODER) instead of #. Thus that person will get notification about your message. – HimBromBeere Aug 03 '15 at 11:07

2 Answers2

1

No difference rather than an abstract class constructor can't be called publicly because otherwise it would defeat the purpose of abstract classes (i.e. they must be inherited and cannot be instantiated directly, thus an abstract class public constructor can be only called by a derived class constructor!).

Matías Fidemraizer
  • 59,064
  • 16
  • 107
  • 181
1

Whilst you cannot instantiate an abstract class it may have a constructor that is called from a derived one. Thus an abstract one should never be public but protected. So the only difference from an API-point of view is that the first cannot be called directly from any arbitrary class while a normal constrcutor can be called allways from everywhere (depending on access-modifier of course).

To be more precise: an Animal-class should probably NEVER be not-abstract. That would mean that there are animals existing that cannot be categorized any further to Cats, Dogs or whatever, but only animals.

HimBromBeere
  • 32,045
  • 4
  • 46
  • 84