<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 封裝與隱藏 ## 課堂代碼-封裝 ~~~java public class Students { /** * 對于封裝的概念,其實是將成員變量隱藏起來,提供對外的方法以供修改和使用 * 如何隱藏起來:使用private關鍵字,控制成員變量的訪問只能在本類中進行訪問使用 * 如何提供對外方法:使用set和get,提供對外暴露的方法 */ private String name; private int age; private String sex; /** * set方法 修改成員變量值 * @param name */ public void setName(String name) { this.name = name; } /** * get方法 獲取成員變量值 * @return */ public String getName() { return this.name; } public int getAge() { return age; } public void setAge(int age) { if(age > 0) { this.age = age; } else { this.age = 0; } } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public Students() { } public Students(String name, int age, String sex) { this.name = name; this.age = age; this.sex = sex; } } ~~~ ~~~java package com.dodoke.demo1; public class StudentsTest { public static void main(String[] args) { Students stut = new Students(); /*stut.name = "曹凱"; stut.age = 25; stut.sex = "男"; stut.age = -10;*/ /** * 使用set方法設置對象的屬性 */ stut.setName("曹凱"); stut.setAge(-10); stut.setSex("男"); /** * 使用get方法獲取對象的屬性 */ System.out.println(stut.getName()); System.out.println(stut.getAge()); System.out.println(stut.getSex()); } } ~~~ ## 課堂代碼-包與引入 ~~~java /** * 包的存在其實是為了分類存放我們創建出來的類,同時也有規定類的唯一性的作用 * package關鍵字來定義包 * 定義包的語句要放在java文件的第一行 */ package com.dodoke.demo1; import com.dodoke.demo2.*; //import com.dodoke.demo2.StudentUse; public class Student { public static void main(String[] args) { //該類的全名叫做com.demo1.Student; com.dodoke.demo1.Student stu = new com.dodoke.demo1.Student(); //如果要引用demo2中Student類 com.dodoke.demo2.Student stu2 = new com.dodoke.demo2.Student(); com.dodoke.demo2.Student stu3 = new com.dodoke.demo2.Student(); com.dodoke.demo2.Student stu4 = new com.dodoke.demo2.Student(); StudentUse stus = new StudentUse(); } } ~~~
                  <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>

                              哎呀哎呀视频在线观看