/*编写一个手机类(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();
}
// TODO 自动生成的方法存根
}
* 方法包括显示手机信息,并编写测试类进行对象的创建*/
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();
}
// TODO 自动生成的方法存根
}
本文展示了如何在Java中定义一个Mobile类,包含品牌(brand)和型号(type)属性,以及显示手机信息的方法。通过创建P1和P2两个对象,并分别设置它们的属性,调用information()方法打印手机型号。
,包括手机品牌(brand)、手机型号(type), 方法包括显示手机信息,并编写测试类进行对象的创建&spm=1001.2101.3001.5002&articleId=78920697&d=1&t=3&u=5ebbdd7d4d844903a0ace1eddf5cdbe6)

被折叠的 条评论
为什么被折叠?



