Cha4-How objects behave

Cha4-How objects behave

  • a class describe what an object knows and what an object does

    • knows — instance variable
    • does — method
  • parameter/argument

    • A method uses parameter.
    • A caller passes argument
    void bark(int numOfBarks){	//parameters
      ...
    }
    
    Dog d = new Dog();
    d.bark(3)	//argument
    
  • Java is pass - by - value

    • pass - by - value
  • method 如果设定返回值,则在方法最后必须要有返回值。但使用时不一定有变量接收

  • Encapsulation

    在这里插入图片描述

  • default value

    • Instance variables always get a default value
    • Local variables do not get a default value. The compiler will complain if you try to use a local variable before the variable is initialized
  • Comparing variables

    • ==
      • compare primitives or to see if two references refer to the same object
    • equals()
      • to see if two different objects are equal
        • such as two different String objects that both represent “hello”
  • Summary

s that both represent “hello”

  • Summary

    在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值