...

/

Questions and Commands

Questions and Commands

This lesson explains what questions and commands are, and how methods can execute them.

Generally speaking, methods play one of two roles:

  • They either answer a question.

or

  • They perform a command.

Examples

For example, if we have a user object, and users have a name, then we would ask the user object for its name by calling the method name: user.name would return the user’s name. Arrays know their size (how many elements they have), so we can ask an array:
...

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy