2021-03-21

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值