Need help understanding the code please


can someone help me understand the main method? I see that calculateShipping is using a method outside of the method scope but still within the class scop. You can call other methods within the same class scope? Meaning before the main method all methods can call on each other? I am so confused, and I apologize if my explanation is confusing. :joy:

The main method is where your program actually runs. Anything outside of it is simply defining the implementation.

Your main method here is initializing 2 Order objects, book and chemistrySet. Since they are objects of type Order, they are both initialized by the Order() constructor (line 5) and additionally have the functionality of the ship() and calculateShipping() methods (note: those methods and constructors will behave according to the specific instance of book and chemistrySet, nothing that happens in book will affect chemistrySet and vice-versa unless they are intended to interact, which they’re not in this case).

In this instance, they each invoke their own method, ship().

2 Likes