Difference between a no-arg constructor and a default constructor in Java

The default constructor is a no-args constructor that the Java compiler inserts on your behalf; it contains a default call to super(); (not supper()) which is the default behavior. If you implement any constructor then you no longer receive a default constructor. JLS-8.8.9. Default Constructor says (in part), If a class contains no constructor declarations, … Read more

Why can’t I refer to an instance method while explicitly invoking a constructor?

Non-static methods are instance methods. This are only accessible in existing instance, and instance does not exist yet when you are in constructor (it is still under construction). Why it is so? Because instance methods can access instance (non-static) fields, which can have different values in different instances, so it doesn’t make sense to call … Read more

Closing a form during a constructor

Calling Close from the constructor of the Form is not possible, as it will call Dispose on a Form that has not yet been created. To close the Form after construction, assign an anonymous event handler to the Load event that closes your Form before it is displayed for the first time: public partial class … Read more

Cannot reference “X” before supertype constructor has been called, where x is a final variable

The reason why the code would not initially compile is because defaultValue is an instance variable of the class Test, meaning that when an object of type Test is created, a unique instance of defaultValue is also created and attached to that particular object. Because of this, it is not possible to reference defaultValue in … Read more