‫Now.
‫Did you know the theory of methods?
‫Let's have a look at the practical aspect of methods.
‫So let's create a method and we start off by an access modifier and I'm just going to use public.
‫Then I add the return type, which is void, and then I give a name.
‫In my case I'm just going to call that write something.
‫So this method is going to write something.
‫And first of all, I start like that.
‫I need curly brackets and in here I simply want to use the console right line.
‫So I'm just going to write something onto the console.
‫And this is going to be I am called from a method so pretty simple and then console but read so nothing
‫too fancy yet and nothing that we haven't seen yet except for this being inside of a method.
‫So now in order to call this method and to run it, we need to call it within the main method.
‫So this method here is a method itself and this method is not public, so it doesn't have an access
‫modifier.
‫I could even get rid of this access modifier, so I could simply say Void, write something, but we'll
‫get into the different access modifiers later on.
‫So this one doesn't have one or main method because it should only be called from this class itself.
‫Then we have void, which means that this method is never going to return anything.
‫And then the name is called Main and because well, it's pretty much our main method, it's the, the
‫one that is really important.
‫And then within the parentheses you have an array of strings which is called ARX, and that's something
‫that we will cover later on.
‫So we haven't seen what arrays are, but we will do so later and you will see what ARGs are as well.
‫So this is our method and here is our starting point as you have read in the last video or have seen
‫in the last video.
‫So whatever we want to run, we need to start it from here.
‫So let's start and call our write something method.
‫Now we do get an error here.
‫We cannot simply call our write something method within the main method because our main method is static.
‫And that's why the write something method has to be static as well.
‫So I add the static term and as you can see, it's between the access modifier and the return type.
‫All right.
‫So.
‫Axis modifier, then static, then return type.
‫And then name of the method or method name.
‫All right, so that's the order.
‫And then afterwards, in parentheses, you have parameter one and parameter two, and they have to be
‫separated by a comma.
‫All right.
‫So that's the usual structure and that's what we have here.
‫So we have a public, which is the excess modifier.
‫We have static, which is used because the main method is static.
‫And static simply means that this method is static and declares a static member which belongs to the
‫type itself rather than to a specific object.
‫That's also something that will make a lot more sense as soon as we get to the point where we use object
‫oriented programming.
‫So for now, just know that whenever you want to call a method within a static method, you need to
‫make the method itself static as well.
‫So for now, as we don't use object oriented programming and the whole, the bigger concepts would rather
‫be difficult to understand.
‫Just let's just keep it at that.
‫Because static is required here, because we want to call it from another static method.
‫All right.
‫And later on, if we have multiple classes, that will not be required anymore, and then we'll have
‫a look at that as well.
‫So here's our result.
‫I am called from a method.
‫So as you can see, we didn't have to write it within our main method.
‫We simply wrote it in here.
‫So you can create very long methods which do loads of things, and then you can simply call them in
‫one line.
‫So this is how we call them and that's how we declare or create them.
‫And a method should usually do one thing.
‫So in this case, this method is just there to write something.
‫So you shouldn't create methods which do 20 different things or something like that.
‫It's best if you keep it simple.
‫So if you want to have a method which does something else, then create an additional method.
‫So a separate method.
‫All right, so let's create an additional method which doesn't just write something what we have here,
‫but which writes something that we want to have.
‫So public static void, write something specific.
‫So our first example, it just wrote anything.
‫Well, whatever was written in here.
‫But now what I want to have, I want to declare what I want to write whenever I call this method.
‫So let's have a look at that.
‫So I'm going to use console right line and now what should I write here?
‫So I don't want to write anything.
‫I want to write something specific.
‫And what that is, is what I'm going to add as a parameter.
‫So here I have parameter one and parameter two, and in here I want to have only one parameter, which
‫is going to be the text of type string.
‫So my text is going to be the parameter and whenever I want to call this method, I can now hand over
‫my text and it will be printed onto the console.
‫So I deliver my text here and now it will write to the console.
‫So let's create read as well or call the read method here as well in order to write it onto the console.
‫And now let's call this write something specific method.
‫And if we just call it like that, we get an error because it says there is no argument given that corresponds
‫to the required formal power parameter.
‫My text.
‫So that means we need to give an argument.
‫All right.
‫So when you create a method, this is called parameter.
‫But when you call the method, what you hand over is the argument.
‫So I'm going to hand over the argument.
‫I am an argument and am called from a method.
‫And here, as you can see, I use exclamation marks as well because this is of type string.
‫So my text is of type string, so I have to hand over a string here.
‫So let's run that as well.
‫And you might wonder I am called from a method is shown, but I am an argument and I'm called from a
‫method is not written onto our console.
‫Why is that.
‫That has to do with this, right?
‫Because console read reads out whatever is written by that point and it doesn't read whatever is written
‫afterwards.
‫So what we can do is get rid of that console right from here and simply call it in here.
‫So.
‫Console dot read.
‫And now let's try it again.
‫And as you can see, I'm called from a method and I am another argument and I'm called from a method.
‫So you have seen how to use arguments and parameters and create methods and use void.
‫And we're going to have a look at other types as well.
‫So in the next video, we're going to have a look at different return types.
‫And then we're also going to use more than just one parameter.