Tuesday 30 October 2018

class - java: Why must I write super() in the first line of the constructor



Possible Duplicate:
Why does this() and super() have to be the first statement in a constructor?






I just learned that at school, but the teacher doesn't know why.



I can think of some good reasons, but I think there are cases when the initializing can be done later in the constructor- before you use the variables form the mother class, for example. OK, the variables should be initialized from the start, but that's not always necessary.



I"m guessing there are a more reasons for that why must super() be placed in the first line of the constructor.




So, why must I write super() in the first line of the constructor, when I'm inheriting a class?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...