What is the first thing that a constructor does? - Cracking the Java Coding Interview

preview_player
Показать описание
Cracking the #Java #Coding #Interview - Question 159: What is the first thing that a constructor does?
Рекомендации по теме
Комментарии
Автор

void answerJavaQuestion(string question, int questionNo){
super.shortAnswer();
lessShortAnswer();
}

plreuokjhg
Автор

This feature is already released in Java 22.

In Java 22, the feature Statements before super() lets you execute code before calling super() in your derived class constructors, this() in your records or enums, so that you could validate the method parameters, or transform values, as required.

aribzaman
Автор

Fun fact the super call is done even before variables are initialized.
In fact if you call a function that modifies the child class from the parent constructor the child class variables may even get overriden by the default values if provided, because they already exist but the initialization process wasn't completed yet.

And yes i ran into this behavior already multiple times.

Speiger
Автор

When will be the new feature you talked about available? In which version of java?

mohamedhafidi
Автор

I think he might have addiction for coffee

ParthaSarathylink