A slightly simplified answer:
public class Book
{
private final String title;
public Book(String title)
{
this.title = title;
}
public Book()
{
this("Default Title");
}
...
}
More Related Contents:
- Why are my fields initialized to null or to the default value of zero when I’ve declared and initialized them in my class’ constructor?
- Java Lombok: Omitting one field in @AllArgsConstructor?
- Why use setters in java instead of constructors? [duplicate]
- Calling a non-static method with constructors using objects from a different class [duplicate]
- What’s wrong with overridable method calls in constructors?
- Can an abstract class have a constructor?
- java “void” and “non void” constructor
- Java Constructor Inheritance
- Is it unnecessary to put super() in constructor?
- Can constructors throw exceptions in Java?
- Purpose of a constructor in Java?
- Calling method from constructor
- Can a constructor in Java be private?
- How to initialize HashSet values by construction?
- Deep copy of an object array
- How does `this` reference to an outer class escape through publishing inner class instance?
- Why can’t Java constructors be synchronized?
- Java: newInstance of class that has no default constructor
- using a variable in constructor in a method outside of constructor
- JPQL: Receiving a Collection in a Constructor Expression
- What does the ‘new’ keyword actually do in Java, and should I avoid creating new objects?
- Why can’t enum constructors be protected or public in Java?
- Default access modifier for a Java constructor
- Initialize field before super constructor runs?
- Is it possible in java to create ‘blank’ instance of class without no-arg constructor using reflection?
- Java. Implicit super constructor Employee() is undefined. Must explicitly invoke another constructor [duplicate]
- Does invoking a constructor mean creating object?
- What is the purpose of a no-arg constructor?
- In Scala, how can I subclass a Java class with multiple constructors?
- Why can’t I refer to an instance method while explicitly invoking a constructor?