Tuesday, October 22, 2019

Void Keyword Definition in Java

Void Keyword Definition in Java 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. Examples 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;   Ã‚  Ã‚  Ã‚  this.author author;   Ã‚  Ã‚  Ã‚  this.publisher publisher;   Ã‚  }   Ã‚  public void displayBookData()   Ã‚  {   Ã‚  Ã‚  Ã‚  System.out.println(Title: title);   Ã‚  Ã‚  Ã‚  System.out.println(Author: author);   Ã‚  Ã‚  Ã‚  System.out.println(Publisher: publisher);   Ã‚  } }

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.