类的延续使用

1 回顾

 

1.1 toString()

 

返回对象属性变成字符串。

System.out.println(c);

1.2 日期

 

1.2.1 Date

 

当前日期时间 (英文输出)

1.2.2 SimpleDateFormat

 

日期的格式转换类

1.2.2.1 Date-->String

 

sdf.format(日期类);

格式:  y   M  d  H m  s

1.2.2.2 String--->Date

 

sdf.parse("2024/05/02")--->Date               Integer.parseInt("123") --->123

1.2.3 Calendar

 

日历类

.get(DATE_OF_MONTH)

2 static

 

静态的。

出现早(进内存时), 只一次

2.1 java的数据存储的模式

 

    static{

        System.out.println("静态代码块");

    }

    {

        System.out.println("代码块....");

    }

    public StaticDemo(){

        System.out.println("无参构造器....");

    

    public static void main(String[] args) {

        StaticDemo s = new StaticDemo();

        StaticDemo s1 = new StaticDemo();

    }

2.2 银行取钱

 

2.2.1 第一种情况

2.2.2 第二种

 

static变成公共空间,由类产生的对象共享数据。

this: 当前对象的引用

this.name: 当前对象的name属性

2.3 使用场景

 

辅助类   创建一个类用来完成输入

1. 输入一个字符串

sc.nextLine();

2. 输入一个数字---》int

Integer.parseInt(sc.nextLine());

3. 输入一个浮点数--->double

Double.parseDouble(sc.nextLine())

3 final

 

最终的,不可变。类似于C语言 const

常量的缺点,不能表示具体的意思。

符号常量,变量+final--》不可变的量

对fianl修饰的变量使用大写字母: XXX_YYY

3.1 出现在变量前(方法)

 

final int a = 3;

a= 4;   //报错

3.2 出现引用前面

 

引用永久绑定当前对象

 final  Car c = new Car();

   c= new Car();

   c=null;

3.3 出现在属性

 

属性必须初始化

不能使用set赋值

4 访问控制符

 

高内聚、低耦合

private (默认) [protected] public

5 this关键字

 

可以调用构造器

tips: this()一定出现在第一句。

6 包装类型

 

对象版的八个数据类型

6.1 int为例

 

Integer a = null;   //引用类型初始值null

    public static int parseInt(String s) throws NumberFormatException {

        return parseInt(s,10);

    }

6.2 包装

 

基本类型--->包装类型

int a = 3;

Integer b = a;  //Integer.valueOf(a)

6.3 拆包

 

包装类型--->基本类型

intValue()

  • 24
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值