void_Keyword

Java void Keyword

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.

Java throws Keyword

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);
}
}

Java throws Keyword

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章