Explain role of constructor in a java application?

Answer Posted / sindhura

A constructor in java has the same name as that of the
class. Whenever the statement such as classname objectname
is encountered, it calls the constructor to initialise the
values for the object. It doesnot return anything and as
soon as the object is created constructor would be called.

ex. : if there is a class called A

A a = new A();
here A a statement would call the constructor immediately
to initialise the values for a object.

Is This Answer Correct ?    10 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Difference between arraylist and vector.

580


Differentiate between a class and an object.

556


How many bits is a string in java?

567


What is Garbage Collection in Java

600


What is parsing and its types?

577






Can java cast null?

593


Why is the singleton pattern considered to be an anti pattern?

465


What is the range of the short type?

572


Does a function need a return?

525


What are abstract classes and anonymous classes?

633


Where are register variables stored?

586


What are abstract methods in java?

638


What is multiple inheritance? Is it supported by java?

518


What does @override mean?

528


What is the use of predicate in java 8?

488