DerivedClass Constructor calling base class constructor

For the instructions below- why is the :base() stated here when the base constructor with no parameters will be called anyways?

public class Derived: MyBaseClass
{
     public Derived() : base()
     {

     }
}
I see that on occasion using the :base(). Isn't the default cause it to call the base constructor anyway? So what is the purpose?
Lawrence AverySystem DeveloperAsked:
Who is Participating?
 
Jacques Bourgeois (James Burger)Connect With a Mentor PresidentCommented:
Oooops. After a short test I see that I am wrong, I know why, and this answer the question.

Some time in the past, I cannot say if it was in the first versions of the framework or when I was programming in C++ at the beginning of the 90's, you had to implicitely call the default constructor. So it almost became an automatism for older programmers. A lot of automatisms stays with us even when they are no longer needed.

Today's compilers probably add the call if you do not do it.

You see the same thing with the habit of setting local variables to null (or Nothing in VB) just before you leave a method. The need for that disappeared at the time of VB4, somewhere around 1995, but a lot of programmer still do it by habit, or because they learned from older programmers that have that habit and do not know that things have changed. Unfortunately, these programmers are also usually the ones that do not know that calling Dispose might do part of the job.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
The base constructor is called by default only if you do not provide a constructor in your own class. From the moment that you define your own constructor, you take control, and you need to decide if you want to call the base constructor or not.
0
 
Lawrence AverySystem DeveloperAuthor Commented:
I ran this code below and it still called MyBaseClass default constructor. You see I am providing my own constructor.

public class Derived: MyBaseClass
{
     public Derived()
     {

     }
}
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Lawrence AverySystem DeveloperAuthor Commented:
Thank you. I thought that might be the case where older programmers leave code that is no longer needed in. And that's fine. No harm. By the way I am one of those types myself. LOL
Thanks again.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
They should have special forums for old programmers :-)

But I would be surprised if you were such an old type as I am. There are very few of my generation who still code and are enjoying the ease with which we do complex things nowadays.

I started programming at a time where a keypunch was the easiest way to enter code in the system,  and you were lucky if you could compile a 50 lines Fortran program more than twice a day in the college computer lab. In some systems, entering code was still done by flippling binary switches.
0
 
Lawrence AverySystem DeveloperAuthor Commented:
Oh no, I did keypunch ibm cards. And I also did Fortran. I am trying to make a come back. I worked for AT&T for nearly 30 years and was outsourced to IBM. Subsequently, IBM outsourced my job after one year to IBM India. From there I took care of a very ill parent for nearly 3 years until they passed. Now I am trying to go back to work at 56 years old. I don't know going back to IT is justifiable but I am a techy at heart. I am studying the .NET world ( App Dev, WCF, ADO and ASP.NET). I hope to go back to work this year even it's at an entry level.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
I am still a couple of years older than you are :-) and I earn my living very well by giving training in VB.NET all around the province of Quebec. Programmers in our age bracket can still be in the game if they enjoy it.

I do not know about the situation where you live, but here, the schools are not churning out IT professionals fast enough. There is a great demand. It's easy to find a job in the field.

And this also holds true for older technologies.

I had a student a few years back who was feeling very bad. RPG and COBOL on mainframe all his life. Absolutely unable to make the switch to the "new world" as he called it. He had a very hard time to grasp simple concepts such as events. He kept asking "I understand the concept, but where is the line that calls the Click?". For him, it was an alien world.

He was 63, close to retirement and feared that he would lose everything because he could not adapt to the new ways of programming. He cried a couple of times during the 4 days session.

I met him a few months ago. All smile. He is now past retirement age... and still working.

Shortly after getting out of my course with suicidal thoughts (I had over 4300 students, and he is the only one that came out that way, I assure you), he met a head hunter that changed his life. She told him how people with his knowledge were in demand. He ended up quitting his job by himself and started his own small consulting service.

"My hourly rate is 3 times your's" he told me. "I refuse more than half of the requests I get because I cannot keep up with the demand".

I wish you to find work in the .NET world. As far as I am concerned, it is a lot more interesting than the oldest ways of programmings. But if not, do not despair. It seems that in a few places, the old experience is still needed.
0
 
Lawrence AverySystem DeveloperAuthor Commented:
Interesting. Thanks the vote of confidence.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.