You may have gotten used to my habit of writing about some special, non-trivial Java feature or usage. This time it will be a little different, at least to start. This is a video tutorial about object initialization. We have an interface. Then we have an abstract class that implements the interface and a concrete class that extends the abstract class. They do nothing except write some strings to the console when they are executed so we can see what order they are executed. They have static initializer blocks, wherever it's possible, non-static initializer blocks, and constructors.

By the way, do you know, and be honest with yourself, whether it's permitted to have a static initializer block inside an interface? If you know Java very well but you cannot answer that question with absolute certainty, it will not hurt to watch this 9-minute tutorial.

And also stay tuned for the second part — when we get back to my real style and let all hell loose.





While you wait for the second tutorial, here is a puzzle:

How is it possible to have an instance of the Concrete class even though calling a new Concrete() throws:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.javax0.classinit.Concrete

If you could not find the answer to the puzzle, watch the second part of the tutorial:





The source code is available from https://github.com/javax0-tutorials/object-initialization.