15 August 2016

Ví dụ nhỏ về kiểu Short trong Java

Examp Short in Java
Java 2016
public class Book {

   // khai bao bien
   private short book_id;
   private String book_name;
   private short book_pages;

   public short getBook_id() {
       return book_id;
   }

   public void setBook_id(short book_id) {
       this.book_id = book_id;
   }

   public String getBook_name() {
       return book_name;
   }

   public void setBook_name(String book_name) {
       this.book_name = book_name;
   }

   public short getBook_pages() {
       return book_pages;
   }

   public void setBook_pages(short book_pages) {
       this.book_pages = book_pages;
   }
 
   public void display(Book book){
  
       System.out.println("Book Name: "+book.getBook_name());
       System.out.println("Book ID: "+book.getBook_id());
       System.out.println("Book Pages: "+book.getBook_pages());
   }

   //Chay chuong trinh
   public static void main(String[] args) {
       Book book = new Book();
       //Setter dua gia tri vao
       book.setBook_id((short)2); //Ep kieu short
       book.setBook_name("Tony Nguyen");
       book.setBook_pages((short)140); //Ep kieu short
       //Goi ham lay gia tri ra
       book.display(book);

 }

}
Output:
Book Name: Tony Nguyen
Book ID: 2
Book Pages: 140

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang