0
What are costructors in java?
5 Respostas
+ 1
Constructors are nothing but methods which has the same name as the "SubClass", and it executes automatically without calling them.
-They are executed before the creation of the "object".
-We can't declare them as static.
-parameter passing wise they are of 2 types.
I. Zero parameter constructor
2. Parameterized constructor
0
one time diclare only automatic run
0
constructors are basically used to initialize there are two types of constructors 1.default 2.parameterized default constructor executes defaultly and parameterized constructor executes when parameter is passed
0
constructor are used to initialise the objects when
we write
class_name object = new class_name ()
It calls the default constructor which is written by java developers only when if didn't created our own constructor
when we call constructor using above statement then memory for attributes respective to class is allocated
0
constructors are the methods having same name as a class.it does not have any return type and is called implicitly, that is, it is called directly when we make an object in main.
there are two types of constructor------
1) parameterised
2) non - parameterized
it is generally used to initialize default values of variables according to their data types.