![]() ![]() Thanks! Let me know if I need to clarify or add more context.īy default, subclass constructor will make a call to super class constructor with no argument. If you could provide some code with your explanations that would be incredibly productive for me. The author doesn't even provide any code to illustrate these points. ![]() Again, I would really appreciate an experience Java developer's explanation here, because I am very confused. Isn't this the case implicitly? The constructors necessarily must have different names, and therefore different signatures, from all of their superclasses. !!! Again, can someone clarify here? He says "create a class that has constructors with entirely different signatures from any of the superclass's constructors". In fact, you can create a class that has constructors with entirely different signatures from any of the superclass's constructors. You don't have to call the constructor in your superclass that has the same signature as the constructor in your class you must call the constructor only for the values you need initialized. The author makes a similar statement in point 2: The line immediately before that, he mentions how constructors are not inherited because they always have the same name as the class so, what does he mean that the constructor with the same signature in the superclass will be called? None of the superclass constructors will have the same signature as the constructors of the subclass because they have different names. But he absolutely loses me when you says "when your class's constructor is called, the constructor with the same signature for all your superclasses also is called". That is, if the superclass constructor requires arguments, you can pass these arguments via super( ). You have to use the super( ) constructor within the subclass constructor to initialize any of the necessary attributes of the superclass. 2)The constructor is only used to Initialize the data members and Instance variables. Concerning the above example, The method Item () has the same name as the class name Item. I think I understand what he's saying here. 1)The constructor is defined with the same name as that of the class. Therefore, initialization can happen for all parts of a class you inherit. This is sufficient much of the time when your class's constructor is called, the constructor with the same signature for all your superclasses also is called. Because a constructor always has the same name as the current class, new constructors are created instead of being inherited. Here are the two most confusing points and I would really appreciate it if some experienced java developers could explain them more clearly.Ĭonstructors cannot be overridden. I think the author just does a very poor job of articulating the points. Okay, so I'm reading this Java book "Java in 21 Days" and the author makes some of what I feel are the most confusing claims in any programming book I've read. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |