+ 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
7 Respostas
+ 3
Sagar Gupta instance p of class Palak is pointing to the Constructor Palak
+ 2
Sagar Gupta Check Now
+ 1
Check this
object initiation should
Palak p = new Palak(10);
https://code.sololearn.com/cbv22j0AA5Pa/?ref=app
0
Ashraf why did you write void before constructor? What difference did it make?
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.
0
Ashraf now plz tell me where does this instance p of class Palak pointing at?
0
Ashraf is string pal variable also pointing at constructor Palak?