为了账号安全,请及时绑定邮箱和手机立即绑定

phone2019622

标签:
Java
package altashna.java.phone2019622;

//main 方法相似window.onlaod=function(){}
public class PhoneMain {
    //初始化
    public static void main(String args[]) {
        //返回值 Phone = 对象实例化 new Phone()
        Phone apple = new Phone();
        //初始化对象的值
        apple.name = "apple";
        apple.type = "x10";
        apple.color = "white";
        apple.price = 5000F;//5000F 等于 5000.0
        apple.call = "打电话";
        apple.stop = "断开";
        //调用对象的行为
        apple.showName();
        apple.showType();
        apple.showColor();
        apple.showPrice();
        apple.call();
        apple.stop();
        //获取返回值,无参数
        String get_info = apple.getIfo();
        System.out.println("get_info:" + get_info);
        //获取返回值,有参数函数
        int get_result = apple.getSum(100);
        System.out.printf("get_result:" + get_result);
    }
}

class Phone {
    String name;
    String type;
    String color;
    float price;
    String call;
    String stop;

    //初始化无参数状态
    public Phone(){
        System.out.printf("");
    }

    //各种按钮的功能
    void showName() {
        System.out.println("name:" + this.name);
    }

    //显示类型
    void showType() {
        System.out.println("type:" + this.type);
    }

    //显示颜色
    void showColor() {
        System.out.println("color:" + this.color);
    }

    //显示价格
    void showPrice() {
        System.out.println("price:" + this.price);
    }

    //打电话
    void call() {
        System.out.println("call:" + this.call);
    }

    //断开
    void stop() {
        System.out.println("stop:" + this.stop);
    }

    //获取信息
    String getIfo() {
        return this.name + "___:" + this.type + "___:" + this.color;
    }

    //计算行为,1到100的累加
    int getSum(int n) {
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum = sum + i;
        }
        return sum;
    }
}


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
Web前端工程师
手记
粉丝
37
获赞与收藏
165

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消