Stranger Things in Java: Constructors

Introduction

What you are reading is the second in a series of articles titled “Stranger things in Java” (find the first article here), inspired by the contents of my book “Java for Aliens”. These articles are dedicated to insights of the Java language. Deepening the topics we use every day, will allow us to master Java coding even in the strangest scenario.

In this post, we will explore some scenarios in which the use of a Java programming base concept, such as the constructor, can hide some pitfalls. In particular, after having clarified some fundamental definitions, we will explore the relationships between constructors and inheritance, constructors and polymorphism, and the hidden work of the compiler.

How to Create Basic Inheritance in JavaScript Constructors

There are four ways to create an object in JavaScript. They are as follows:

  1. Object as literal
  2. Constructor Invocation Pattern
  3. The create() method
  4. Using class after ES6

The implementation of inheritance varies according to the object creation method. In this post, I am going to explain creating inheritance between a function constructor.