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

What does += mean in java?

580


Why do we use variables?

517


Explain the selection sort algorithm and state its time complexity?

615


Why is inheritance used in java?

613


which one is more efficient int x; 1. if(x==null) 2.if(null==x) state which one either 1 or 2?

9249






What is bufferedreader in java?

584


What is the purpose of a default constructor?

583


What is the difference between array list and vector in java?

511


How does queue work in java?

532


How you can force the garbage collection?

542


How do you achieve polymorphism in java?

525


Can I import same package/class twice?

501


What is bool mean?

575


Which collections are thread safe in java?

483


What is public/private protected in java?

548