What is meant by constructor?

Answer Posted / bindhu

Constructor is special type of member function that will
automatically invoke when an object creates. The purpose of
constructor is for the initialization of instance
variables. A constructor having the same name as that of
class name. It may have arguments but doesn't return
anything.
If we want to initialize all objects of the same class
with same values, use default constructor.Otherwise, we can
use parameterized constructor if we want to initialize
objects of the same class with different values. If we
don't specify any constructor , compiler will use default
constructor with garbage value.

Is This Answer Correct ?    35 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is ‘has a’’ relationship in java?

726


Justify your answer that you can't define a method inside another method in java, if you can then how?

606


What do you mean by platform independence? What is an interface?

563


What do you mean by byte code?

517


Why are functions called methods in java?

533






What is static method with example?

618


Can you make a constructor final in Java?

628


Explain the protected field modifier?

594


Why are arrays useful in java?

544


What is protected access modifier?

579


What is parameters example?

555


How to sort an array from smallest to largest java?

547


What are adapter classes?

601


Is arraylist an object in java?

602


Why is core java important?

576