编写一个手机类(Mobile),包括手机品牌(brand)、手机型号(type), 方法包括显示手机信息,并编写测试 ...

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:39   2919   0
/*编写一个手机类(Mobile),包括手机品牌(brand)、手机型号(type),
* 方法包括显示手机信息,并编写测试类进行对象的创建*/
package cyff;


public class Mobile {// 定义Mobile类
String brand, type;// 成员变量


public void information() {// 成员方法
System.out.println(type);
}


public static void main(String[] args) {


Mobile P1 = new Mobile();// 声明并创建对象
P1.brand = "华为";// 给P1的属性赋值
P1.type = "华为7i";
Mobile P2 = new Mobile();// 声明并创建对象
P2.type = "华为";// 给P2的属性赋值
P1.information();
P2.information();
}
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP