public class Shirt{ public int shirtID = 0; public String description = "-----"; public char colorCode = 'U' ; //R=red,G=green,B=blue,W=white public double price = 0.0; //顯示 Shirt 相關資料 public void displayInformation(){ System.out.println("Shirt ID: " + shirtID); System.out.println("Description: " + description); System.out.println("Shirt Color: " + colorCode); System.out.println("Shirt's price: " + price); } }
Java 物件的利用:
public class Demo{ public static void main(String[] args){ Shirt myShirt = new Shirt(); myShirt.displayInformation(); } }