0

I am confused in constructor...

Give an exmple and teach me.. Add what is the use of constructor there

18th Sep 2016, 5:33 PM
aman kumar
aman kumar - avatar
4 Answers
+ 3
rules to use constructor 1).it's name must be the same as of class name 2).it must not have any return type And working is very much similar to the function/method. it is used to create instance of a class. JVM always creates a default constructor for every class . Constructor is of two types 1).default 2). parameterized Ex:- class A { A()//default constructor {} A(int b)// parameterized constructor {} //rest of the code....... }
19th Sep 2016, 12:37 AM
Ankur Sharma
Ankur Sharma - avatar
+ 1
Constructor is a special function used to initialise variables in a class. it is defined as- eg- class_name(int var) { int a=var; } here we have passed a variable var and assigned it to a which is a member of Class class_name.
18th Sep 2016, 7:36 PM
Abhishek Sharma
Abhishek Sharma - avatar
+ 1
Here is complete explanation about constructor: http://javabasictoadvanced.blogspot.co.id/2016/06/constructor.html
19th Sep 2016, 4:18 AM
Aula Muttaqin
Aula Muttaqin - avatar
0
Thanku abhishek
18th Sep 2016, 8:17 PM
aman kumar
aman kumar - avatar