Skip to content
José da Cruz

Enterprise Architect, and Life Thinker

José da Cruz

Enterprise Architect, and Life Thinker

Java Learning: Default Constructor

josedacruz, January 3, 2024

The objective of a constructor is to create an object from a class blueprint.
Since the main idea of this action is to create and initialize an object, it makes sense to use the class’s name as the method’s name.
This is a special method since it has no explicit return type. I say explicit because it returns a reference to the object created and allocated in the heap. We could say it returns this, the reserved word that can be used inside the class to reference the current object. Some languages call it self, which seems very appropriate.
Another distinction from other method calls is the word new; this is how the compiler knows we are targeting a constructor method and not a local method.

BankAccount ba = new BankAccount(); // OK: the word new signals to choose a constructor method

BankAccount ba = BankAccount(); // ERROR: Will try to call a local method

All classes should have at least one constructor, meaning you should have a method with no return type and with the same class’s name.
Most of the classes don’t need, at the start, specific logic or values to be initialized when the object is created. To avoid always writing an empty constructor, if none is provided, the Java compiler assumes a default constructor exists.

class BankAccount {
	private String customerId;
	private String customerName;

	// optional
	public BankAccount() {}
}

class SavingsAccount {
	// There is an empty constructor here!
}


public class Finances {
	public static void main(String... args) {
		BankAccount ba = new BankAccount();
		SavingsAccount sa = new SavingsAccount();
	}
}

Related

java java

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • architecture (167)
  • artificial-intelligence (6)
  • books (2)
  • courses (4)
  • decision-frameworks (4)
  • finances (1)
  • java (8)
  • life-improvement (20)
  • metrics (3)
  • observability (2)
  • puzzles and challenges (3)
  • reviews (1)
  • security (8)
  • Soft Skills (1)
  • spring-boot (36)
  • Systems Thinking (3)
  • GitHub Weekly: AI Agent Tools Trending Right Now (November 2 – November 8, 2026)
  • Designing a Distributed Session Store: Why Sticky Sessions Break Under Load
  • Essential Reading: Release It! — Why Production Is a Different Game Than Development
  • GitHub Weekly: Top 10 Trending Repos (October 26 – November 1, 2026)
  • GitHub Weekly: Architecture & Infra Tools Worth a Look (October 19 – October 25, 2026)
©2026 José da Cruz | WordPress Theme by SuperbThemes