0

Can anyone give an example where constructor of a class called but the instantiation of that class not happened?

15th Jul 2018, 1:55 PM
Sumit Basu
Sumit Basu - avatar
4 odpowiedzi
+ 5
class somthing{ somthing(){ System.out.print(System.out.print("Class Constructor"); } } //main(){ Somthing obj = new Somthing();//Calls constructor }
15th Jul 2018, 2:28 PM
D_Stark
D_Stark - avatar
+ 5
Sumit Basu yes thats correct the constructor is invoked when the object is created if theres no constructor a default one is created 👍
15th Jul 2018, 6:33 PM
D_Stark
D_Stark - avatar
0
Thank you..but new keyword will create the object of something.. please correct me if I am wrong
15th Jul 2018, 5:05 PM
Sumit Basu
Sumit Basu - avatar
0
Thanks Stark..but then object is created anyway by ur program..then how can we achive the scenario..
16th Jul 2018, 6:36 AM
Sumit Basu
Sumit Basu - avatar