Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*1. 撰寫一個帶有 default 建構式(亦即不接收任何引數)的 class,並
- 在其中列印某些訊息。請為此class 產生一些物件。*/
- /*2.請為上題中的 class 增加一個多載化建構式,令它接收一個 String
- 引數,並印出你所提供的訊息。*/
- /*3. 請為題 2的 class 產生一個 object references array,但不需實際產
- 生物件來附著於array。執行此程式時,請注意建構式中的初始化
- 訊息有沒有被列印出來。*/
- /*4. 繼續題 3的內容,產生一些物件,將它們附著於 references array。*/
- class Printer{
- Printer(){System.out.println("印表機啟動囉~~~");}
- Printer(String S){
- System.out.println(S);
- }
- void Prt(String A){
- System.out.println(A);
- }
- static int[] Storage = {5,6,7,8};
- }
- public class Practice4 {
- public static void main(String[] args) {
- Printer HEHE = new Printer();
- HEHE.Prt("我是誰~~~");
- Printer YA = new Printer("這是第二題喔");
- //從0開始喔,而且Storage要是Static
- System.out.println(Printer.Storage[0]);
- }
- }
Add Comment
Please, Sign In to add comment