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修饰
        属性:类属性,类变量        实例属性,实例变量
        方法:类方法            实例方法
    
                类名.属性    对象.属性
        调用方式:    类名.方法()    对象.方法()
                对象.属性    
                对象.方法()
        归属:        类        单个对象
    
  • 相关阅读:
    linux动态库(.so)和静态库(.a)的区别
    LeetCode刷题笔记和想法(C++)
    tf-idf、朴素贝叶斯的短文本分类简述
    计算机操作系统(第三版)读书笔记
    react hook封装一个排序按钮,有效果图
    react使用fetch封装请求的方法-简单易懂
    react开发企业中后台产品、政务门户网站的一些总结
    git常见命令以及基本使用
    Linux系统下fd分配的方法
    netfilter-IPv4实现框架分析(一)
  • 原文地址:https://www.cnblogs.com/wojiatingting/p/7015610.html
Copyright © 2011-2022 走看看