Notizen
Ohne Titel
Inhalt der Notizen (2)
Seite 1
a class, how to create an object.
Then once you create an object, how many ways we can assign the data into the object variables using
object reference variable and also using a method and using constructor.
So three different ways of assigning the data into the variables we have seen in this data class.
So now today we are going to focus more on method and constructor.
So today we have used method and constructor, but today we will discuss a little bit more about method
and constructor.
So first of all, what is method?
So what is a method?
A method is a block of statements.
A method is a block or a group of statements which will perform certain tasks.
So when I create a one method, suppose when it will perform some tasks.
We need to call that method.
We have to call that method.
Then it will perform the task.
So a method is a block or group of statements which will perform certain tasks and we have to call the
method through the object.
So when you create a method, how to create a how to call that method through the object reference variable,
we need to create an object.
And through the object reference variable, we can invoke the method.
So how we can create a method.
There are multiple ways we can create a method.
It depends on our requirement.
Like sometimes method will not take any parameters.
Also, it will not return any value and sometimes method will not take any parameters, but it will
perform certain task.
And then finally it will return some value.
And suppose sometimes the method will take parameters and it will not return any value, or sometimes
method will also take the parameters and also return a value.
So multiple combinations of methods we can create.
It depends completely based on our requirement.
So the first thing when you create a method, we have to call the method through the object variable.
Second thing is method may take parameters or may not take parameters.
Similarly, a method may return a value or may not return a value multiple cases we can create.
So these are the four different cases.
Now we'll see practically how we can create a methods with parameters, without parameters, with return
value without returning value.
And then we will see how we can call those types of methods.
Okay, So let's go to Eclipse.
And let's create a new package for today.
Indy nine.
So I'll create a new class.
That's a new class.
I'll name it as greetings.
My last name is.
Greetings.
Last name should start with uppercase character.
I'll name it as a greetings and not taking main method, so I will create main method in the separate
class.
So I'm just creating a plain class here.
So here we will create a different type of methods.
Okay.
Let it.
Let it be for now.
Later, we will add some code.
And also I will create one more class which is having main method.
Let's create another class.
I will name it as Greetings Main.
Here, I'm taking main method.
Click on Finish.
So now I have two classes.
This is Greetings class.
And this is the greetings Main class.
So I have separated main method in another class.
Now, in the greetings class I will create different types of methods.
So variables are methods.
Both are not mandatory.
You can create variables.
Sometimes you may not have methods, or you can create a methods without variables.
This is up to you.
So, but normally when you talk about class definition, a class is a collection of variables and methods.
So let me create a first method.
The first method is here no parameters and also no return value.
No parameter, no return value.
How to create a method.
So no return value means what?
It is a void.
Return type is a wide void means a no return value.
And I'm giving some name to the method, I'd say.
Greetings.
Greeting one.
This is one method I created.
Greeting one.
If I look at this method, return type is void means it will not return anything for us.
And greeting one is the name of the method.
And that can be anything.
You can give any name to the method.
No problem.
And the empty bracket is representing no parameters.
No parameters.
Parameters in the sense some input to the method.
When you pass an input to the method by using that input, the method will perform certain task that
is called parameters.
And sometimes we can also call them as
a class, how to create an object.
Then once you create an object, how many ways we can assign the data into the object variables using
object reference variable and also using a method and using constructor.
So three different ways of assigning the data into the variables we have seen in this data class.
So now today we are going to focus more on method and constructor.
So today we have used method and constructor, but today we will discuss a little bit more about method
and constructor.
So first of all, what is method?
So what is a method?
A method is a block of statements.
A method is a block or a group of statements which will perform certain tasks.
So when I create a one method, suppose when it will perform some tasks.
We need to call that method.
We have to call that method.
Then it will perform the task.
So a method is a block or group of statements which will perform certain tasks and we have to call the
method through the object.
So when you create a method, how to create a how to call that method through the object reference variable,
we need to create an object.
And through the object reference variable, we can invoke the method.
So how we can create a method.
There are multiple ways we can create a method.
It depends on our requirement.
Like sometimes method will not take any parameters.
Also, it will not return any value and sometimes method will not take any parameters, but it will
perform certain task.
And then finally it will return some value.
And suppose sometimes the method will take parameters and it will not return any value, or sometimes
method will also take the parameters and also return a value.
So multiple combinations of methods we can create.
It depends completely based on our requirement.
So the first thing when you create a method, we have to call the method through the object variable.
Second thing is method may take parameters or may not take parameters.
Similarly, a method may return a value or may not return a value multiple cases we can create.
So these are the four different cases.
Now we'll see practically how we can create a methods with parameters, without parameters, with return
value without returning value.
And then we will see how we can call those types of methods.
Okay, So let's go to Eclipse.
And let's create a new package for today.
Indy nine.
So I'll create a new class.
That's a new class.
I'll name it as greetings.
My last name is.
Greetings.
Last name should start with uppercase character.
I'll name it as a greetings and not taking main method, so I will create main method in the separate
class.
So I'm just creating a plain class here.
So here we will create a different type of methods.
Okay.
Let it.
Let it be for now.
Later, we will add some code.
And also I will create one more class which is having main method.
Let's create another class.
I will name it as Greetings Main.
Here, I'm taking main method.
Click on Finish.
So now I have two classes.
This is Greetings class.
And this is the greetings Main class.
So I have separated main method in another class.
Now, in the greetings class I will create different types of methods.
So variables are methods.
Both are not mandatory.
You can create variables.
Sometimes you may not have methods, or you can create a methods without variables.
This is up to you.
So, but normally when you talk about class definition, a class is a collection of variables and methods.
So let me create a first method.
The first method is here no parameters and also no return value.
No parameter, no return value.
How to create a method.
So no return value means what?
It is a void.
Return type is a wide void means a no return value.
And I'm giving some name to the method, I'd say.
Greetings.
Greeting one.
This is one method I created.
Greeting one.
If I look at this method, return type is void means it will not return anything for us.
And greeting one is the name of the method.
And that can be anything.
You can give any name to the method.
No problem.
And the empty bracket is representing no parameters.
No parameters.
Parameters in the sense some input to the method.
When you pass an input to the method by using that input, the method will perform certain task that
is called parameters.
And sometimes we can also call them as
Seite 2
a class, how to create an object.
Then once you create an object, how many ways we can assign the data into the object variables using
object reference variable and also using a method and using constructor.
So three different ways of assigning the data into the variables we have seen in this data class.
So now today we are going to focus more on method and constructor.
So today we have used method and constructor, but today we will discuss a little bit more about method
and constructor.
So first of all, what is method?
So what is a method?
A method is a block of statements.
A method is a block or a group of statements which will perform certain tasks.
So when I create a one method, suppose when it will perform some tasks.
We need to call that method.
We have to call that method.
Then it will perform the task.
So a method is a block or group of statements which will perform certain tasks and we have to call the
method through the object.
So when you create a method, how to create a how to call that method through the object reference variable,
we need to create an object.
And through the object reference variable, we can invoke the method.
So how we can create a method.
There are multiple ways we can create a method.
It depends on our requirement.
Like sometimes method will not take any parameters.
Also, it will not return any value and sometimes method will not take any parameters, but it will
perform certain task.
And then finally it will return some value.
And suppose sometimes the method will take parameters and it will not return any value, or sometimes
method will also take the parameters and also return a value.
So multiple combinations of methods we can create.
It depends completely based on our requirement.
So the first thing when you create a method, we have to call the method through the object variable.
Second thing is method may take parameters or may not take parameters.
Similarly, a method may return a value or may not return a value multiple cases we can create.
So these are the four different cases.
Now we'll see practically how we can create a methods with parameters, without parameters, with return
value without returning value.
And then we will see how we can call those types of methods.
Okay, So let's go to Eclipse.
And let's create a new package for today.
Indy nine.
So I'll create a new class.
That's a new class.
I'll name it as greetings.
My last name is.
Greetings.
Last name should start with uppercase character.
I'll name it as a greetings and not taking main method, so I will create main method in the separate
class.
So I'm just creating a plain class here.
So here we will create a different type of methods.
Okay.
Let it.
Let it be for now.
Later, we will add some code.
And also I will create one more class which is having main method.
Let's create another class.
I will name it as Greetings Main.
Here, I'm taking main method.
Click on Finish.
So now I have two classes.
This is Greetings class.
And this is the greetings Main class.
So I have separated main method in another class.
Now, in the greetings class I will create different types of methods.
So variables are methods.
Both are not mandatory.
You can create variables.
Sometimes you may not have methods, or you can create a methods without variables.
This is up to you.
So, but normally when you talk about class definition, a class is a collection of variables and methods.
So let me create a first method.
The first method is here no parameters and also no return value.
No parameter, no return value.
How to create a method.
So no return value means what?
It is a void.
Return type is a wide void means a no return value.
And I'm giving some name to the method, I'd say.
Greetings.
Greeting one.
This is one method I created.
Greeting one.
If I look at this method, return type is void means it will not return anything for us.
And greeting one is the name of the method.
And that can be anything.
You can give any name to the method.
No problem.
And the empty bracket is representing no parameters.
No parameters.
Parameters in the sense some input to the method.
When you pass an input to the method by using that input, the method will perform certain task that
is called parameters.
And sometimes we can also call them as
Informationen
- Beschreibung
- Notiz am Ohne Titel, erstellt von naveen guntupalli am 24/11/2023.
- Erstellt von
- naveen guntupalli · Nov 2023
- Aktualisiert
- 24 Nov 2023
- Aufrufe
- 2
- Bewertung