Overview: 2.3.0

  • Methods are a set of instructions that define behaviors for a class
  • To call a method, use the dot operator
    • turguggins.forward() calls turguggins’s forward method
  • Object methods or non-static methods must be called on an object, not a class
    • Work on attributes of the object
  • method calls need parenthesis
    • used to give parameters
    • you still need parenthesis if you don’t have parameters

Procedural Abstraction: 2.3.1

  • procedural abstraction allows a programmer to utilize a method without knowing how it works
    • the brakes in your car work even if you don’t know how
  • Use a method signature/header to figure out what methods do

  • Methods inside the same class can call each other using methodName()
    • otherwise you need to create an instance of the class, then call the method

Null Pointer Exceptions

  • You must initialize an object before you can call it’s methods
  • declaring an object reference without setting it to a new object will make the value null
  • If you call a method on a null object, you get a NullPointerException
    • pointer is another name for a reference

Summary: 2.3.3

  • methods are a set of instructions that define behaviors of objects in the class
  • dot notation is used to execute an object’s method
    • object.method()
  • method signature is the name followed by a parameter list
    • parameter list consists of the type and name of each parameter
  • procedural abstraction is the concept where you can use a procedure without knowing exactly what each piece of the procedure does
  • a method or constructor call interrupts the sequential flow of statements, as the program will jump to execute the statements included in the method before continuing
  • NullPointerException happens when you try to use an object reference which is null
    • This happens when the object has not been initialized yet
  • object method or non-static method is a method which must be called on an object of the class
    • utilizes an object’s specific attributes
  • static method or class method can be called without an instance of a class