面想对象的分析(OOA,Object-Orientrd Analysis)
面向对象的设计(OOD, Object-Oriented Design)
面向对象的编程(OOP, OBJECT-Oriented Programming)
面向对象:
两大要素:类和对象
四大特征:封装、继承、多态、抽象
方法的重载:
1 方法的名字必须要求相同
2 参数不同
2.1参数的个数but1行 5行 12行 17行
2.2参数的类型不同 12行和17行函数
2.3参数的顺序不同 12行23行
参数的类型的顺序相同,但参数的名字不同,不能构成重载。推断出,判断不同函数根据函数的 返回权限 返回值 函数的名字(参数的类型)
public Phone(){
}
//构造方法 包含全部的参数,全参构造方法
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 ){
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行不呢个构成重载
public Phone(int gaodu ,int kuandu,int zhongliang){
weight = zhongliang ;
width = kuandu ;
height = gaodu ;
}
toString()
所有的类都继承Object(对象),因此:所有的类中都有toString()方法为了方便查看,一般都会复写
public String toString() {
return "{" + width + "" + color + " " + weight + "}" ;
}
基本数据类型(byte, short, int ,long float double )使用 ==比较
引用数据类型(数组String) 自定义类,需要使用equals方法比较
public String toString() {
return "{" + width + "" + color + " " + weight + "}" ;
}
基本数据类型(byte, short, int ,long float double )使用 ==比较
引用数据类型(数组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 ;
/*
构造方法:1一定没有返回值 2 方法的名字必须和类名完全一致
*/
//无参构造方法,不管写不写,系统都会生成
public Phone(){
}
//构造方法 包含全部的参数,全参构造方法
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 + "}" ;
}
}