215k views
4 votes
To call a method on an object, do you follow the object with a period, then the method name, and finally a set of parenthesis? Enclose any parameters in the parenthesis.

User Rodniko
by
8.9k points

1 Answer

3 votes

Final answer:

Yes, to call a method on an object, you follow the object with a period, then the method name, and finally a set of parenthesis. Enclose any parameters in the parenthesis.

Step-by-step explanation:

Yes, to call a method on an object, you follow the object with a period, then the method name, and finally a set of parenthesis. Enclose any parameters in the parenthesis.

For example, let's say we have an object called 'car' and a method called 'startEngine' that takes no parameters. To call the 'startEngine' method on the 'car' object, we would write: car.startEngine().

If the method requires parameters, you would provide the values within the parentheses. For instance, if the 'startEngine' method takes a parameter called 'fuelType', you would write: car.startEngine('gas').

User BunjiquoBianco
by
8.3k points