面想對象的分析(OOA桩警,Object-Orientrd Analysis)
面向?qū)ο蟮脑O計(OOD, Object-Oriented Design)
面向?qū)ο蟮木幊蹋∣OP, OBJECT-Oriented Programming)
面向?qū)ο螅簝纱笠兀侯?和 對象
四大特征:封裝线脚、繼承枷餐、多態(tài)疙渣、抽象
方法的重載:
1 方法的名字必須要求相同
2 參數(shù)不同
2.1參數(shù)的個數(shù)but1行 5行 12行 17行
2.2參數(shù)的類型不同 12行和17行函數(shù)
2.3參數(shù)的順序不同 12行23行
參數(shù)的類型的順序相同且轨,但參數(shù)的名字不同酒甸,不能構(gòu)成重載魄健。推斷出,判斷不同函數(shù)根據(jù)函數(shù)的 返回權限 返回值 函數(shù)的名字(參數(shù)的類型)
public Phone(){
}
//構(gòu)造方法 包含全部的參數(shù)插勤,全參構(gòu)造方法
public Phone(double kuandu ,double gaodu ,int zhongliang ,String yanse){
width = kuandu ;
height = gaodu ;
weight = zhongliang ;
color = yanse ;
}
//構(gòu)造函數(shù) 構(gòu)造器 構(gòu)造方法
public Phone(double kuandu,double gaodu ,int zhongliang){
weight = zhongliang ;
width = kuandu ;
height = gaodu ;
}
public Phone(double kuandu,int gaodu ){
weight = zhongliang ;
width = kuandu ;
height = gaodu ;
}
public Phone(double gaodu ,double kuandu,int zhongliang){
weight = zhongliang ;
width = kuandu ;
height = gaodu ;
}
public Phone(int gaodu ,double kuandu,int zhongliang){
weight = zhongliang ;
width = kuandu ;
height = gaodu ;
}
//和23行不呢個構(gòu)成重載
public Phone(int gaodu ,int kuandu,int zhongliang){
weight = zhongliang ;
width = kuandu ;
height = gaodu ;
}
toString()
所有的類都繼承Object(對象)沽瘦,因此:所有的類中都有toString()方法為了方便查看,一般都會復寫
public String toString() {
return "{" + width + "" + color + " " + weight + "}" ;
}
基本數(shù)據(jù)類型(byte农尖, short析恋, int ,long float double )使用 ==比較
引用數(shù)據(jù)類型(數(shù)組String) 自定義類盛卡,需要使用equals方法比較
public String toString() {
return "{" + width + "" + color + " " + weight + "}" ;
}
基本數(shù)據(jù)類型(byte绿满, short, int 窟扑,long float double )使用 ==比較
引用數(shù)據(jù)類型(數(shù)組String) 自定義類喇颁,需要使用equals方法比較
package edu.xcdq;
public class Main {
public static void main(String[] args) {
Phone xiaomi11 = new Phone() ;
xiaomi11.weight = 255;
xiaomi11.height = 135 ;
xiaomi11.width = 55 ;
xiaomi11.color = "color" ;
Phone iphone = new Phone(56,136,256,"土豪金");
System.out.println(iphone);
}
}
package edu.xcdq;
/**
* @qvthor liuwenzheng
* @date 2021/4/20 14:48
*/
public class Phone {
public double width ;
public double height ;
public int weight ;
public String color ;
/*
構(gòu)造方法:1一定沒有返回值 2 方法的名字必須和類名完全一致
*/
//無參構(gòu)造方法,不管寫不寫嚎货,系統(tǒng)都會生成
public Phone(){
}
//構(gòu)造方法 包含全部的參數(shù)橘霎,全參構(gòu)造方法
public Phone(double kuandu ,double gaodu ,int zhongliang ,String yanse){
width = kuandu ;
height = gaodu ;
weight = zhongliang ;
color = yanse ;
}
public Phone(double kuandu,double gaodu ,int zhongliang){
weight = zhongliang ;
width = kuandu ;
height = gaodu ;
}
public Phone(double kuandu,int gaodu ,int zhongliang){
weight = zhongliang ;
width = kuandu ;
height = gaodu ;
}
public Phone(int gaodu ,double kuandu,int zhongliang){
weight = zhongliang ;
width = kuandu ;
height = gaodu ;
}
public Phone(int gaodu ,int kuandu,int zhongliang){
weight = zhongliang ;
width = kuandu ;
height = gaodu ;
}
public void startUp(){
System.out.println("手機即將開機");
}
public void suopin(){
System.out.println("手機即將鎖屏");
}
//方法的復寫
public String toString() {
return "{" + width + "" + color + " " + weight + "}" ;
}
}