创建对象并初始化
/*** Created by Administrator on 2018/10/31.*/
public class zhu {public static void main(String[] args){lei car1=new lei("紅色",6);//創建對象并初始化,給參數賦值car1.color="白色";car1.boud ="焚天";car1.count=7;car1.weight =4.56f;System.out.println(car1.color);System.out.println(car1.xianzheng+"噸"); public class lei {String color;int count;String boud;float weight;float xianzheng=10.43f;public lei(String myColor,int myCount){color=myColor;count=myCount;}
}
?
People p1=new People(20,"張三");System.out.println(p1.age);System.out.println(p1.name );System.out.println(car1.color );System.out.println(car1.count );//類對象名,成員變量 } } public class People {int age;String name;public People(int myAge,String myName){age=myAge;name=myName;} }?
轉載于:https://www.cnblogs.com/llhhcc/p/9882502.html
總結
- 上一篇: ElementUI el-table 在
- 下一篇: 洛谷P2016战略游戏