Java 從基礎到進階學習之路---類編寫以及文檔凝視.

來源:互聯網
上載者:User

標籤:技術分享   get   數字   分享   div   閱讀   學生   color   ogr   

Java之前在學習過,基礎知識還沒有忘光,並且這些進階語言實在是太像,所以那些資料類型,或者迴圈控制流程,以及標準裝置等等就直接略過不說了.

只是一些重大概念會穿插在文章的介紹中.

So,這些文章適合於那些有一定進階物件導向語言基礎的人閱讀.

我們首先編寫一個學生類.其主要要求要熟悉的內容是:

關於類構造器(構造方法)的認識和理解.

關於方法的編寫.

關於成員變數 & this 的使用,

熟悉了這些內容後,我們就能夠依照以下的類圖編寫這個類了.

構造器的參數有姓名,性別,學號.

類圖例如以下:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3Vvb2w=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" >


我寫的參考的代碼例如以下:

我把全部的屬性都寫成了private類型的,由於這些資料都可寫一套set和get方法.....


/*** Description:* <br> Blog:<a href = "http://suool.net" target="blnak"> Suool's Blog </a> * <br> Copyright (c), 2014-2015, SuooL  * <br> This program is writeen by Crazy Java.* <br> Program name: student.java * @author: SuooL* @version: 1.0.0*/ public class student{/// 私人變數private String Stu_name;private String Stu_sex ;private long Stu_Id ;private int Stu_age;/*** Student 的構造方法* @param name  構造的學生執行個體姓名 * @param sex   構造的學生執行個體性別* @param Id 構造的學生執行個體學號,開頭數字不為零*/public student(String name, String sex, long Id){this.Stu_name = name;this.Stu_sex = sex  ;this.Stu_Id = Id    ; }/*** 設定年齡的方法* @param age 要設定的學生的年齡*/public void setAge(int age){this.Stu_age = age;System.out.println("You set the age of the student " + this.Stu_name + " is " + this.Stu_age);}/*** 擷取指定學生的學號* @return 返回長整型學號值*/public long getID(){System.out.println("You get the ID of the student " + this.Stu_name + "is" + this.Stu_age);return this.Stu_Id;}/*** 主方法* @param args 命令列參數*/public static void main(String[] args) {// 構造學生對象student Tom = new student("Tom", "Boy", 122511042); student Jelly = new student("Jelly", "Girl", 122511043);Tom.setAge(20);System.out.println(Tom.getID());}}

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3Vvb2w=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" >

產生的JavaDoc例如以下.

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3Vvb2w=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" >



Next,下一節寫一個小遊戲,命令列版的無AI的五子棋.

事實上就是對數組和標準輸入輸出的練習吧.


“If you don‘t make the time to work on creating the life you want, you‘re eventually going to be forced to spend a LOT of time dealing with a life you don‘t want.” --Kevin Ngo

Java 從基礎到進階學習之路---類編寫以及文檔凝視.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.