0

In a class,if we have a constructor and methods with same name and without argument is this is possible to have like this?

please tell me

29th Jul 2017, 4:25 PM
vani s
7 Réponses
+ 6
Yes, it's possible. Constructors don't have any return type, not even void. This is how constructors can be differentiated from other methods. The following code is valid: class Person{ // data fields Person(){ // constructor } void Person(){ // this is a method } }
29th Jul 2017, 6:28 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 1
Yes ,Constructor and method(function) can have same arguments ...As constructor doesn't have any return type so constructor n method can be differentiated ...Hope u understood ...
6th Aug 2017, 4:41 PM
Nirmal Singh Rajput
Nirmal Singh Rajput - avatar
+ 1
@Vani yes it is possible to have constructor n method having same argument ,same name in one class ....
6th Aug 2017, 4:43 PM
Nirmal Singh Rajput
Nirmal Singh Rajput - avatar
0
Which language ?
29th Jul 2017, 4:35 PM
sneeze
sneeze - avatar
0
in java
29th Jul 2017, 5:10 PM
vani s
0
is it possible to have a constructor and method both having same argument,same name in one class?!
29th Jul 2017, 5:11 PM
vani s
0
Sorry, I don't know java. please add java to your tags
29th Jul 2017, 5:43 PM
sneeze
sneeze - avatar