zoukankan      html  css  js  c++  java
  • 2

    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);
        }
    }
    View Code
    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);
        }
    
    }
    View Code
    public class TestDay03 {
    
        public static void main(String[] args) {
            Day03 w = new Day03();
            w.print();
        }
    
    }
    View Code
     1.方法重载
        1.1方法重载:方法名一样,参数列表不一样
                注意:重载返回值类型和访问修饰符无关。
        
         2.static和final
        static:静态图
            用static修饰的属性,直接可以类名,方法名访问
        final:最终的
            用final修饰的属性,他的值初始化后,不能再改变
    
        后++,先把本身的值作为表达式的值,然后本身+1
        例:a++
        前++,先把本身+1,然后再把值作为表达式的值。
        例:++a
        后--,先把本身的值作为表达式的值,然后本身-1
        前--,先把本身-1,然后再把值作为表达式的值。
    
              static,非private修饰    非static,private修饰
        属性:类属性,类变量        实例属性,实例变量
        方法:类方法            实例方法
    
                类名.属性    对象.属性
        调用方式:    类名.方法()    对象.方法()
                对象.属性    
                对象.方法()
        归属:        类        单个对象
    
  • 相关阅读:
    Strom在本地运行调试出现的错误
    能否通过六面照片构建3D模型?比如人脸,全身的多角度照片,生成3D模型。?
    怎么识别自己的眼型?眼型图片参照
    用opencv检测人眼并定位瞳孔位置
    仿射变换
    二维图像的三角形变换算法解释
    Labeled Faces in the Wild 人脸识别数据集
    【图像处理】计算Haar特征个数
    人脸识别技术大总结(1):Face Detection & Alignment
    基于Policy Gradient实现CartPole
  • 原文地址:https://www.cnblogs.com/wojiatingting/p/7015610.html
Copyright © 2011-2022 走看看