package aa;
public class Student {
//属性 变量
String name;//姓名
int age;//年龄
//方法
public void eat() {
System.out.println(“干饭啦!!!”);
}
public void sleep() {
System.out.println(“干饭啦!!!”);
}
public void study() {
System.out.println(“干饭啦!!!”);
}
package aa;
public class rjh {
public static void main(String[] args) {
//1.导包
//我需要使用的Student类,和我自己的rjh在同一个包里面,所以省略导包语句不写。
//2.创建,格式;
//类名称 对象名 = new类名称();
//根据Student类创建了一个名为stu的对象
Student stu = new Student();
//3.使用其中的成员变量,
//对象名.成员变量名
stu.name=“唐浩”;
stu.age=19;
System.out.println(stu.name);
System.out.println(stu.age);
stu.eat();
stu.sleep();
stu.study();
}
}
package aa;
public class Phone {
//成员变量
String brand;//品牌
double price;//价格
String color;//颜色
//成员方法
public void call(String who) {
System.out.println("给"+who+"打电话");
}
public void sendMessage() {
System.out.println("群发短信");
}
}
package bb;
public class rjh2 {
public static void main(String[] args) {
//根据phone类,创建一个为one的对象
//格式:类名称 对象名 = new 类名称();
Phone one = new Phone();
one.brand=“OPPO”;
one.price=9999;
one.color=“星空紫”;
System.out.println(one.brand);
System.out.println(one.price);
System.out.println(one.color);
one.call("任正非");//给任正非打电话
one.sendMessage();//群发短信
}
}
学号:2020080605035