Skip to content

Instantly share code, notes, and snippets.

@m0smith
Created January 27, 2024 22:57
Show Gist options
  • Save m0smith/11d4d483a7b03d47b5e123cace29f21f to your computer and use it in GitHub Desktop.
Save m0smith/11d4d483a7b03d47b5e123cace29f21f to your computer and use it in GitHub Desktop.
Example 2 for Default Constructor
class Book {
String title;
// A no-argument constructor
Book() {
title = "Unknown";
}
}
public class Main {
public static void main(String[] args) {
Book mysteryBook = new Book();
System.out.println("Book title: " + mysteryBook.title); // Outputs: Book title: Unknown
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment