补充类的进阶

MVC : Model View Controller 模型 视图 控制器

视图 -》 控制器 -》模型

模型 -》 控制器 -》 视图

增删改查 ===》数据的流转

流程图:

开始:椭圆

输入输出操作:平行四边形

正常操作:矩形

判断:菱形

结束:圆形

方法的重载:

1 方法的名字必须要求相同

2 参数不同

    2.1 参数的个数不同   1 行 5行 12行 17行函数

    2.2 参数的类型不同  12 行和17行函数

    2.3 参数类型的顺序不同  12行和23行函数

            参数的类型顺序相同,但参数的名字不同,不能构成重载。推断出,判断不同的函数根据函数的  **访问权限  返回值  函数的名字 ( 参数的类型)**
    public Phone () {
        System.out.println("我被调用了,有一个对象产生了");
    }
    // 构造方法 包含全部的参数 全参构造方法
    public Phone(double kuandu , double gaodu , int zhongliang , String yanse) {
        width = kuandu ;
        height = gaodu;
        weight = zhongliang;
        color = yanse;
    }
    // 构造函数
    public Phone (double kuandu , double gao, int zhongliang ) {
        width = kuandu;
        height = gao;
        weight = zhongliang ;
    }
    public Phone (int kuandu , int gao, int zhongliang ) {
        width = kuandu;
        height = gao;
        weight = zhongliang ;
    }

    public Phone ( int zhongliang ,double kuandu , double gao  ) {
        width = kuandu;
        height = gao;
        weight = zhongliang ;
    }
    // 和23行不能构成重载
    public Phone (int gao , int kuandu, int zhongliang ) {
        width = kuandu;
        height = gao;
        weight = zhongliang ;
    }
     // this 当前对象
    public Phone(double width , double height , int weight , String color) {
        this.width = width ;
        this.height = height;
        this.weight = weight;
        this.color = color;
    }

toString()

所有的类都继承自Object(对象),因此所有的类中都有toString()方法

为了方便查看,一般都会复写

    // 方法的复写
    public String toString() {
        return "{" + this.width +" "+ this.height  +" "+ this.weight +" "+ this.color + "}";
    }

== equals

基本数据类型(byte short int long float double) 使用==比较

引用数据类型(数组 String) 自定义的类,需要使用equals方法比较

代码的执行顺序:

public class Demo03 {
    // 普通类属性
    int size = 0;

    // 代码块
    {
        size = 10;
    }

    // 静态变量
    static int count =30;
    // 静态代码块
    static  {
        count  = 10;
    }

    public Demo03() {
        System.out.println("构造方法");
        System.out.println(count);  // 10
        System.out.println(size);    // 10
    }
}

1 、静态static修饰的内容在整个类中最先执行

 1. 1 static同时修饰变量和代码块,谁写在前面先执行谁

2 、代码块和类属性其次执行

2.1 普通类属性和代码块,谁写在前面先执行谁

3、构造方法的执行

static

1 、static修饰的内容,没有对象也可以存在,换句话说:有没有对象在内存中都存在

2、普通的属性,方法,内部类,要求有对象才可以存在具体的内存中

1、2 两条原则在语法上不能冲突 具体表现在:静态的成员不能直接使用非静态的成员

final 最终的

被final修饰的成员值在程序中不能发生改变

你可能感兴趣的:(补充类的进阶)