1. 程式人生 > 資訊 >訊息稱小米已收購自動駕駛公司 DeepMotion,前者市值漲超 5%

訊息稱小米已收購自動駕駛公司 DeepMotion,前者市值漲超 5%

建立物件 面對物件:以類的方式組織程式碼,以物件組織(封裝)資料。 抽象 三大特性:封裝性、繼承性,多型性 初始化物件使用new關鍵字建立物件 類中的構造方法:1、必須和類的名字相同。2、必須設有返回型別,也不能寫void public class mate{   String name;   int age;   int sno; } ===================================================================== public class Student {   public static void main(String [] agrd){      mate xiaoMin= new mate();//初始化      mate xiaohong=new mate();     xiaoMin.name ="xiaomin";     xiaoMin .age =19;     xiaoMin .sno =1213;     xiaohong .name ="xiaohong";     xiaohong .age =18;     xiaohong .sno =1214;     System.out.println(xiaoMin .name ) ;    } } ===================================================================== class Qishi {   private int leve;   private String name;   private int hp;   private int mp; //protected,private,public ==>面向物件程式設計 都有 //函式的 過載和重寫 //不帶引數的建構函式 => public + 類名   public Qishi() {} //帶參的建構函式   public Qishi(int leve,String name,int hp,int mp) {     this.leve = leve;     this.name = name;     this.hp = hp;     this.mp = mp; } //構造方法   public void setName(String name) {     this.name = name;   }   public String getName() {     return this.name;   }   public void setLeve(int leve) {     this.leve = leve;   }   public int getLeve() {     return this.leve;   }   public void setHp(int hp) {     this.hp = hp;   }   public int getHp() {     return this.hp;   }   public void setMp(int mp) {     this.mp = mp;   }   public int getMp() {     return this.mp;   } } 這裡如果沒有寫構造方法的話系統是會預設生成建構函式的。
物件的應用: 引用型別:基本型別 物件是通過引用來操作的:棧-->堆 屬性:欄位field 成員變數 預設初始化: 數字:0 0.0 char:u000 布林值:false 引用:null 修飾符 屬性型別 屬性名=屬性值 物件的建立和使用: 必須使用new 物件屬性、物件方法