Overview: 2.5.0

  • all methods have return types
    • void means it doesn’t return anything
    • others return a value back

Get methods: 2.5.1

  • return the value of instance variables
    • getWidth() gets the value of width
  • you need to do something with the value returned from this variable

toString: 2.5.2

  • toString is a common method which converts an object to a string
    • not mentioned this method is inherited from java.lang.Object, so every object has this

Methods with Arguments and Return Values: 2.5.3

  • Methods with return values and arguments are like math functions
    • given an input, they produce an output
  • return statement returns the value indicated in the return type
    • return 5; returns the integer 5

Summary: 2.5.5

  • some methods return values
  • the return value of a method must be stored in a variable or used in an expression
    • return types have data types