Files
javaSE-0113/day06/src/com/inmind/object01/Demo03.java

34 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind.object01;
//对面向对象-引用类型对象作为方法参数
public class Demo03 {
public static void main(String[] args) {
//买一台星空黑的尺寸5.5价格4999的小米手机
Phone p1 = new Phone();
p1.brand = "小米";
p1.price = 4999;
p1.size = 5.5;
p1.color = "星空黑";
showPhone(p1);
p1.show();
System.out.println("---------");
//买一台土豪金的尺寸6.1价格8999的苹果手机
Phone p2 = new Phone();
p2.brand = "苹果";
p2.price = 8999;
p2.size = 6.1;
p2.color = "土豪金";
showPhone(p2);
p2.show();
}
//在非描述类的类中定义方法一般加上static
//定义一个方法,接收一个手机,展示它的属性
public static void showPhone(Phone phone) {//引用数据类型,作为参数
//展示下对应手机的属性
System.out.println(phone.brand);
System.out.println(phone.price);
System.out.println(phone.size);
System.out.println(phone.color);
}
}