I think Sun is a little beautiful,
"The new operator creates an instance of the class by allocating memory for the new object and returning a reference to that memory. The new operator also calls the constructor of the object."
So, yes a
is a reference to the BankAcc
object that you created using the new
operator, i.e. you assign =
return new
to variable a
, which is a reference to an instance of type BankAcc
As for your second point, this can be done (compiled and executed), but I donβt see many reasons why you would like it if the constructor did not do something βimportantβ.
Edit: please refer to Tudor's answers for examples where unlinked copying applies
Ti
source share