+ 1

Can we not use instance of a class to call a function?

I have made p as an instance of class palak and trying to call constructor Palak https://code.sololearn.com/cQ6WPZlaCcDc/?ref=app

7th Apr 2020, 9:04 PM
Sagar Gupta
Sagar Gupta - avatar
7 Respostas
+ 3
Sagar Gupta instance p of class Palak is pointing to the Constructor Palak
7th Apr 2020, 9:28 PM
Gouse Basha
Gouse Basha - avatar
+ 2
Sagar Gupta Check Now
7th Apr 2020, 9:20 PM
Gouse Basha
Gouse Basha - avatar
+ 1
Check this object initiation should Palak p = new Palak(10); https://code.sololearn.com/cbv22j0AA5Pa/?ref=app
7th Apr 2020, 9:06 PM
Gouse Basha
Gouse Basha - avatar
0
Ashraf why did you write void before constructor? What difference did it make?
7th Apr 2020, 9:14 PM
Sagar Gupta
Sagar Gupta - avatar
0
Just put this in main method. Palak p = new Palak(10); A constructor is invoked only when an object of that class is created. An object is created using new keyword.
7th Apr 2020, 9:20 PM
Avinesh
Avinesh - avatar
0
Ashraf now plz tell me where does this instance p of class Palak pointing at?
7th Apr 2020, 9:24 PM
Sagar Gupta
Sagar Gupta - avatar
0
Ashraf is string pal variable also pointing at constructor Palak?
7th Apr 2020, 9:31 PM
Sagar Gupta
Sagar Gupta - avatar