Answer Posted / ravina gaikwad
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 ? | 0 Yes | 0 No |
Post New Answer View All Answers
I don’t want my class to be inherited by any other class. What should I do?
What will happen if there is a default method conflict as mentioned above and we have specified the same signature method in the base class instead of overriding in the existing class ?
What is overriding in java?
What is math in java?
What is the purpose of the main method?
What is variable argument in java?
What are the advantages of functions?
Why we go for collections in java?
Why does java have two ways to create child threads?
Name few java 8 annotations ?
What are some examples of variable costs?
How do you write a good declaration?
What is a bubble sort in java?
What is meant by class loader? How many types are there? When will we use them?
Difference between nested and inner classes ?