A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Why do we use constructor instead of functions or method in oops concept?

I have seen a lot of weakness in the concept of constructor in C++,  Java or C#.  Sometimes I have not seen only in students but also in mentor while they mentoring.

Previously mentioned,  why?
Let's discuss about this. Guys you may all known that method can initialize our non-static variable when they called if they have already defined in such a manner.

But,  Actually not exactly happens.  Guy's without any call of constructor, you can never create an object.  If you think about instance,  it means today you have to meet with pure object concept that I am going to explore:

An instance of class always contains null values of object field.  But an object can be filled out of values if constructors are involved.

If you want to do with methods or functions, it reinitiallize the value of object.

Hence,  our conclusion is that both ways are different since no need to call constructors and no future problem of garbage  values in objects fields. So we have good concept of constructor to initialized the fields of class. It is highly recommended way.