All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.
I thought that A2 println method is an unreachable statement.
because this(); will call another constructor.
someone can explain me please the steps when calling A with String argument?
thanks
Maybe is for my english, but I understood creating objects inside the class C, hence there are 3 forms.
"Class C can be instantiated only in two ways by users of class C."
"user of a class" means some other code that uses this class. It cannot be inside the class, because the one who writes code inside the class is the developer of that class, not the user.
If you like our products and services, please help us by posting your review here.
Class C has three constructors, which means you can create an object of class C using any of the three constructors. For example, if you create an object of C using new C(), then the C1 constructor of C is invoked. This has a call to super(), which means, the default no-args constructor of B (not shown in the code) is invoked. This default constructor of B contains a call to super(), which means, constructor A1 of A is invoked. Thus, you can see that one constructor of each class is invoked.
You can now work out the path for other constructors of C in the same manner.
If you like our products and services, please help us by posting your review here.
Am I correct in saying that since the 2nd one has this() in the first line, it doesn't need to go looking in B or A class?
I guess what I'm not seeing is the 3rd constructor's path. I don't see the super for this one, (public C(int i) {}) in B or A classes. So how does this one work?
Your question requires too many fundamental details about constructors to be explained in post. You need to go through the fundamentals of constructors from a good book. Once you do that your doubt will be cleared immediately. Section 9.3 of Hanumant's OCAJP 8 Fundamentals covers this nicely.
If you like our products and services, please help us by posting your review here.
I'm glad you recommended this book. I've read in a couple of other books about the relationship between the constructors, but section 9.3 of this book really drives it home. Thanks