構(gòu)造方法

package edu.xcdq;
public class Phone {
    public double width;
    public double high;
    public int weight;
    public String color;

    /*
    * 構(gòu)造方法:沒(méi)有返回值 方法的名字和類(lèi)名需要完全一致
    * 通過(guò)構(gòu)造方法,可以創(chuàng)建對(duì)象
    * */
    public  Phone(){
        System.out.println("我被創(chuàng)建了");
    }
    /*
    * 構(gòu)造方法
    * 含有全部的參數(shù)
    * */
   /* public Phone(double kuan,double gao,int zhongliang,String yanse){
        width = kuan;
        high = gao;
        weight = zhongliang;
        color = yanse;
    }*/
    public Phone (double width, double high,int weight,String color){
        this.width =width;
        this.high = high;
        this.weight = weight;
        this.color =color;
    }
        /*
            構(gòu)造函數(shù)
            含有部分參數(shù)
        */
        public Phone (double kuan ,double gao , int zhongliang){
            width = kuan;
            high = gao;
            weight = zhongliang;
        }
        /*
        * 方法的重載
        *   要求 : 1. 方法的名字相同 2. 參數(shù)不同
        *                        2.1 參數(shù)類(lèi)型不同
        *                        2.2 參數(shù)的個(gè)數(shù)不同
        *                        2.3 參數(shù)類(lèi)型的調(diào)用順序不同
        * */
    public void kaiji(){
        System.out.println("手機(jī)正在開(kāi)機(jī)");
    }
    public void kaiji(int i,double j){

    }
    public void kaiji (double j , int i){

    }
    public void kaij (int i,int j,int k){

    }
    /*private int kaiji(){

    }*/
    public void guanji(){
        System.out.println("手機(jī)正在關(guān)機(jī)");
    }
    public String toString() {
        return "["+this.width + this.high +this.weight + this.color+ "]";

    }
}


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容