Java void is a keyword that indicates that a method is empty without a return type, and although a constructor method can never have a return type, there is no void keyword in its declaration.
The void keyword indicates that the method is empty if it has no return type. However, even though a constructor method can never have a return type, there is no void keyword in its declaration.
Example
The displayBookData() method does not use the return type shown by the void keyword.
Note that the constructor method Book(String, String, String) does not use the void keyword, even though it has no 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; this.author = author; this.publisher = publisher; } public void displayBookData() { System.out.println("Title: " + title); System.out.println("Author: " + author); System.out.println("Publisher: " + publisher); } }
Recommended reference "Java Video Tutorial"
The above is the detailed content of What is Java void. For more information, please follow other related articles on the PHP Chinese website!