亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消