Tuesday, November 5, 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); Ã Ã } }
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.