课后作业之手机类(指针法)

题目:

            编写一个手机类(Mobile),包括手机品牌(brand)手机型号(type),方法包括显示手机信息,并编写测试类进行对象的创建。

源代码:


package org.java.application;
//手机类
class Mobile{
    String brand;
    String type;
    //有参构造函数构造一个对象
    public Mobile(String brand , String type){
        this.brand = brand;
        this.type = type;
    }
    public boolean foo(String brand , String type){
        System.out.println("brand:"+brand+"----"+"type:"+type);//输出手机信息
        return true;
    }
}
//有参构造函数构造一个对象
class Test{
   Mobile mobile = new Mobile("iphone","02");// 实例化Mobile类的对象
   void func(){
        mobile.foo(mobile.brand,mobile.type);
   }
}


//创建匿名对象调用.func方法
public class Application{
    public static void main(String[]args){
        new Test().func();
    }
}

课后作业之手机类(指针法)