方法重载



    1.1方法重载:方法名一样,参数列表不一样
            注意:重载返回值类型和访问修饰符无关。
    
     2.static和final
    static:静态图
        用static修饰的属性,直接可以类名,方法名访问
    final:最终的
        用final修饰的属性,他的值初始化后,不能再改变

    后++,先把本身的值作为表达式的值,然后本身+1
    例:a++
    前++,先把本身+1,然后再把值作为表达式的值。
    例:++a
    后--,先把本身的值作为表达式的值,然后本身-1
    前--,先把本身-1,然后再把值作为表达式的值。

          static,非private修饰    非static,private修饰
    属性:类属性,类变量        实例属性,实例变量
    方法:类方法            实例方法

            类名.属性    对象.属性
    调用方式:    类名.方法()    对象.方法()
            对象.属性    
            对象.方法()
    归属:        类        单个对象
public class Day03 {
        //品种
        private int strain;
        //年龄
        private int age = 8;
        //昵称
        private String name = "小灰灰";
        //健康
        private int health = 100;
        //亲密
        private int love = 100;
        //打印信息
    //构造方法(默认构造方法)
        public Day03(String name,int strain){
            this.name = name;
            this.strain = strain;
        }
        public Day03(){
            this.name="畹町";
            this.age=18;
            this.love=99;
            this.health=100;
            System.out.println("-----执行dog构造方法-----");
        }
        public void print(){
            System.out.println(this.name+","+this.age+","+this.strain);
    }

}
public class Day02 {
    String name;
    int health=99;
    int love=99;
    String sex;
    //常量
    //public static final 常量名=常量值;
    
    //注意:1.final最终的,修饰的变量不能被修改
    //2.变量名:所有字母大写,多个单词用_分隔
    public void print(){
        System.out.println("宠物自白:我的名字叫"+name+",健康值"+health+",亲密度"+love+",性别"+sex);
    }
}
public class TestDay03 {

    public static void main(String[] args) {
        Day03 w = new Day03();
        w.print();
    }

}
原文地址:https://www.cnblogs.com/abc199812/p/7019642.html