<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] # 標準類的寫法 ## 類 * 成員變量 1. 無參構造方法+setXXX() 2. 帶參構造方法 * 構造方法 1. 無參構造方法 2. 帶參構造方法 * 成員方法 1. getXXX() 2. setXXX() ## 面向對象的標準案例 ``` public class Student { //成員變量 private String name; private int age; //構造方法 public Student(){} public Student(String name,int age){ this.name=name; this.age=age; } //成員方法 public void setName(String name){ this.name=name; } public String getName(){ return name; } public void setAge(int age){ this.age=age; } public int getAge(){ return age; } } public class StudentDemo { public static void main(String[] args) { //無參構造方法+setXxx()方法 Student s=new Student(); s.setName("小明"); s.setAge(18); System.out.println(s.getName()+"---"+s.getAge()); //帶參構造方法 Student s2=new Student("小明", 18); System.out.println(s2.getName()+"---"+s2.getAge()); } } ``` ### 例:類名作為形式參數 ``` public class Student { public void study(){ System.out.println("好好學習,天天向上"); } } public class Teacher { /** * @Title: test * @Description: 測試學生學習的方法 * @param s */ public void test(Student s){ s.study(); } } ``` ### //類名作為形式參數時:其實這里實際需要傳遞的是該類的對象 ``` public class Test { public static void main(String[] args) { Teacher t=new Teacher(); Student s=new Student(); t.test(s); } } ``` ### 例:類名作為返回值案例 返回的其實是該類的對象 ``` public class Student { /** * @Title: study * @Description: 學習方法 */ public void study(){ System.out.println("好好學習,天天向上"); } } public class Teacher { /** * @Title: getStudent * @Description: 獲取學生對象 * @return */ public Student getStudent(){ Student s=new Student(); return s; } } /* * @ClassName: Test * @Description: 通過Teacher對象得到Student對象,然后調用Student對象的方法 * @date 2017年11月11日 上午10:22:21 * Company www.igeekhome.com * * 如果方法的返回值是類名:其實返回的是該類的對象 */ public class Test { public static void main(String[] args) { Teacher t=new Teacher(); Student s=t.getStudent(); s.study(); } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看