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
What does += mean in java?
Why do we use variables?
Explain the selection sort algorithm and state its time complexity?
Why is inheritance used in java?
which one is more efficient int x; 1. if(x==null) 2.if(null==x) state which one either 1 or 2?
What is bufferedreader in java?
What is the purpose of a default constructor?
What is the difference between array list and vector in java?
How does queue work in java?
How you can force the garbage collection?
How do you achieve polymorphism in java?
Can I import same package/class twice?
What is bool mean?
Which collections are thread safe in java?
What is public/private protected in java?