0
点赞
收藏
分享

微信扫一扫

Cha4-How objects behave

独兜曲 2022-03-25 阅读 26
java

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

    在这里插入图片描述

举报

相关推荐

0 条评论