What is meant by constructor?

Answer Posted / dinesh

All the objects that are created must be given initial
values.There are two approach for this.
1)Using the dot operator to access the instance variables
and then assign values to them individually---This is a
tedious approach.
2)Use of getData method to initialize each object
individually.eg:add.getData(10,15)
To make this simpler Java supports a special type of method
called a Constructor,that enables an object to initialize
itself when it is created.Constructor have the same name as
the class itself and they do not specify a return type,not
even void,bcoz they return the instance of the class itself.

Is This Answer Correct ?    23 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an immutable class?

624


Explain the difference between private, public, package and protected in java?

611


Write a method to check if input string is palindrome?

587


What does a method signature consist of?

521


What are the advantages of autoboxing?

544






Explain about the interpreter in java?

638


How do you represent a space in regex java?

532


What is a method vs function?

579


What is math in java?

578


What is an escape character in java?

542


What is serialization in java?

571


What is the flag in java?

616


What is the platform?

540


Explain java coding standards for interfaces?

640


What is namespace in java?

550