ELI5: Explain Like I'm 5

Method (computer science)

Okay kiddo, so you know how people use computers to get things done, right? Like playing games, browsing the internet, and typing documents? In order to do all of those things, the computer needs to know what to do and in what order to do it.

That's where methods come in.

Basically, a method is a set of instructions that tells the computer what to do. You can think of it like a recipe for a cake. Just like a recipe tells you what ingredients to use and when to mix them in order to make a cake, a method tells the computer what steps to take and in what order to take them to perform a specific task.

For example, let's say you want to make a computer program that prints out the message "Hello, world!" on the screen. You would use a method called "println" to do this. The println method tells the computer to print whatever message you give it to the screen. So, you would write something like this in your program:

println("Hello, world!");

When your program runs, the computer will see this line of code and know to use the println method to print the message "Hello, world!" on the screen.

There are lots of different methods that you can use depending on what you want your program to do. Some methods might be used for doing math calculations, while others might be used for manipulating text or images.

So, to sum it up: think of methods as sets of instructions that tell the computer what to do, just like a recipe tells you how to make a cake. And just like there are lots of different recipes for different types of cakes, there are lots of different methods for different types of tasks in computer programming.
Related topics others have asked about: