Home  >  Article  >  Java  >  What is Java void

What is Java void

藏色散人
藏色散人Original
2019-01-18 09:49:5510312browse

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.

What is Java void

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn