- class Test {
- public static void main(String[] args) {
- Student s = new Student();
- s.name = "赵子龙";
- s.age = 18;
- System.out.println(s.name + "同学的年龄是" + s.age);
- s.study();
- s.sleep();
-
- System.out.println("-----------");
- Phone p = new Phone();
- p.brand = "iPhone7S";
- p.price = 6880;
- System.out.println(p.brand + "的价格是" + p.price);
- p.call();
- p.sendMessage();
- p.playGame();
- }
- }
- class Student {
- String name;
- int age;
- int gender;
- public void study(){
- System.out.println("学生学习");
- }
- public void sleep(){
- System.out.println("学生睡觉");
- }
- }
- class Phone {
- String brand;
- int price;
- public void call(){
- System.out.println("打电话");
- }
- public void sendMessage(){
- System.out.println("发短信");
- }
- public void playGame(){
- System.out.println("玩游戏");
- }
- }
复制代码
|
|