JAVA基礎的package樣本

來源:互聯網
上載者:User
昨天第3講主要講了點OOP的概念和package的用法,後者是新接觸的,下面是這一講的作業,比較簡單僅供newbie參考,老師要求用JBuilder,但那東東畢竟不是開源的,雖然自己水平很爛其實用開源和不用開源沒什麼區別~但從精神上還是贊同開源
~Because the Open-Source Community is our hope that we can beat back to Microsoft.
今天天氣還是有點熱,晚上的rugby已經準備好~~lets fight...wait a minute~fight for what?

/*
建立一個名為child的子包,其基礎包名為parent,子包中應該包含一個Location類.
Location類包含一個名為disp()的方法,用於顯示"Everything is meaningless"的訊息.
建立一個名為ParentTest的類,使它匯入此子包,並調用Location類的disp()方法.
注意:package說穿了就是檔案夾,以parent.child為例,將這個Location.java編譯後的Location.class檔案
應該放到parent/child/Location.class
*/
//含Location類的package
package parent.child;
public class Location {

    public void disp()
    {
        System.out.println("Everything is meaningless");
    }
}

//用於測試的類ParentTest
import parent.child.Location;
class ParentTest {
    public static void main(String[] args)
    {
        Location a=new Location();
        a.disp();
    }
}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.