Home > Java > javaTutorial > body text

What is Java void

藏色散人
Release: 2020-10-21 10:09:09
Original
10285 people have browsed it

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);
  }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!