April 2019
Intermediate to advanced
360 pages
9h 17m
English
OOP affords us the opportunity to use method call chaining. That is the process of making multiple method calls in a single statement. Here is the syntax:
object.method1().method2().method3().method4();
Using the syntax provided previously, we can walk through the process of method call chaining. The object first calls method1(), which returns the calling object. Next, that returned object calls method2(), which returns the calling object. You can see the process here. It works from left to right.
So, we can implement this in our Driver class, as shown here:
// Example using method call chainingBicycle myBike5 = new Bicycle(24, 418.50, 17.2, "Green");myBike5.setColor("Peach").setGears(32).outputData("Number 5");
Before ...
Read now
Unlock full access