The Void Keyword

Closeup of hands using a computer

TommL / Vetta / Getty Images

The void keyword in Java denotes that a method does not have a return type. However, even though a constructor method can never have a return type, it does not have the void keyword in its declaration.


The method displayBookData() does not have a return type as shown by the use of the void keyword. Note that the constructor method Book(String, String, String) does not use the void keyword even though it too does not have a return type.

 public class Book {

  private String title;
  private String author;
  private String publisher;

  public Book(String title, String author, String publisher)
    this.title = title; = author;
    this.publisher = publisher;

  public void displayBookData()
    System.out.println("Title: " + title);
    System.out.println("Author: " + author);
    System.out.println("Publisher: " + publisher);
mla apa chicago
Your Citation
Leahy, Paul. "The Void Keyword." ThoughtCo, Aug. 26, 2020, Leahy, Paul. (2020, August 26). The Void Keyword. Retrieved from Leahy, Paul. "The Void Keyword." ThoughtCo. (accessed June 25, 2022).