定义类:
///定义手机类/属性:创建品牌、颜色、价格//行为:打电话给xxx 群发短信publiclicch class phone { String brand; String color; int price; public void call(String name){ System.out.println("给"+ name +“打电话”; } public void sendMessage(){ System.out.println(“输出群发短信”; }}///编写手机测试类,创建两个对象并赋值public class phoneTest { public static void main(String[] args) { phone ph1=new phone(); ph1.brand="小米"; ph1.color="白色"; ph1.price=4999; System.out.println(ph1.brand); System.out.println(ph1.color); System.out.println(ph1.price); ph1.call(张三); ph1.sendMessage(); System.out.println("------------"); phone ph2=new phone(); ph2.brand="华为"; ph2.color="黑色"; ph2.price=6999; System.out.println(ph2.brand); System.out.println(ph2.color); System.out.println(ph2.price); ph2.call(李四); ph2.sendMessage(); }}