Calling Methods Without Parameters
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()callsturguggins’sforwardmethod
Object methodsornon-static methodsmust be called on an object, not a class- Work on
attributesof the object
- Work on
- method calls need parenthesis
- used to give parameters
- you still need parenthesis if you don’t have parameters
Procedural Abstraction: 2.3.1
procedural abstractionallows 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/headerto 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
nullobject, you get aNullPointerExceptionpointeris another name for a reference
Summary: 2.3.3
methodsare a set of instructions that define behaviors of objects in the classdot notationis used to execute an object’s methodobject.method()
method signatureis the name followed by a parameter list- parameter list consists of the type and name of each parameter
procedural abstractionis the concept where you can use a procedure without knowing exactly what each piece of the procedure does- a
methodorconstructorcall interrupts the sequential flow of statements, as the program will jump to execute the statements included in themethodbefore continuing NullPointerExceptionhappens when you try to use an object reference which is null- This happens when the object has not been initialized yet
object methodornon-static methodis a method which must be called on an object of the class- utilizes an object’s specific attributes
static methodorclass methodcan be called without an instance of a class

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
This was adapted from the CS Awesome curriculum, which was created by
Barbara Ericson, Beryl Hoffman, and many other CS Awesome contributors. All rights reserved.
CS Awesome is licensed under CC BY-NC-SA 4.0.