#2 Method in Java | Java for Beginners | Java Method
Автор: SG Tutorial
Загружено: 2021-07-07
Просмотров: 5658
Описание:
#2 Method in Java | Java for Beginners | Java Method
About this video:
This tutorial will explain about Java Methods in simple way...
Timestamp :
0:22 What is a Method?
1:04 How to declare Method?
1:19 Syntax to declare Method
2:02 Access-modifier
2:44 Return-Type
4:02 Method Parameters
5:31 How to call Method?
6:36 Example
Links of Tutorials:
To learn about basics of Java click here 👇 • Java Tutorials for Beginners | Java course...
Method Overloading:
• Method Overloading in Java | Java for Begi...
Method Overriding:
• Method Overloading in Java | Java for Begi...
Java Inheritance:
• Java Inheritance | Java for Beginners
Java class and object :
• #1 class and object in java | Java for Beg...
Java Constructor :
• #5 Java Constructor | Java Tutorial for Be...
Constructor Overloading:
• Constructor Overloading in Java | Java for...
Java Instance Block :
• #6 Instanse Block in Java | Java Tutorials...
Java variable :
• #3 Variable in Java| Java Tutorial | What ...
Variable declaration and initialization :
• #4 Variable Declaration and Initialization...
Why do we need programming language?:
• Why we need Programming Language? | Java f...
Notes:
1. What is a Method ?
2. How to declare Method?
2.1 Syntax
2.2 Access_modifiers
2.3 Return_Type
2.4 Method_Name
2.5 Parameters/ Arguments
3. How to call method?
3.1 How to call static method?
3.2 How to call non- static method?
1. What is a Method ?
Method is a action or function used to perform a certain task to get the
expected results.
For example:
ringing, calling ,send data, received data these are the actions/functions of mobile phone
and we can write this function using a method in java..
2. How to declare Method?
To declare a method,we need to follow the syntax..
2.1 Syntax:
access-modifier return-type method-name (param-list)
{
//code;
}
2.2 Access_modifiers:
access - modifier controls the access level/ scope of method..
Access - modifier is also called as access-specifier..
We can use four types of access-modifiers for method in Java..
Public,Private,Protected,
and Default..
2.3 Return_Type:
return_type specifies what type of value a method will returns.
For example:
If you order a pizza..
then you will get pizza as a return..
food orderPizza()
{
return pizza;
}
return statement is used to return any value or data..
So here, method has food return type
Because this method is returning a pizza and pizza is type of food..
Similarly,
If method has an int return type then method returns an integer value.
If method has void returnType then method won't return any value..
2.4 method_name:
A method name should typically represent what its task is.
2.5 Parameters/ Arguments:
Sometimes we have to pass data to the method to perform certain task / operation on that data and that data is called parameters or also called as arguments..
3.How to call a method?
To get the expected result, we need to execute the method and to execute the method we need to call a method..
3.1 How to call static method? static method is belong to a class i.e static method work for a class..
To call a static method in Java, write the method’s name followed by two parentheses()and a semicolon(;)
For example,
addNumbers();
Or you can call static method using a class name..
For example:
Test.addNumbers();
here, Test is class name and addNumbers () is static method's name.
3.2 How to call non- static method?
non- static method is belong to an object of a class
That means, non-static method work for an object and that's why,
to call a non-static method first you need to create an object then using that object you can call non-static method..
For example:
// Creating an object
Test obj = new Test();
// Calling non-static method using an object
obj.addNumbers();
So here, obj is an object name.
___________End_________
Thank you so much for watching 🙏
#javamethod #methodinjava #calljavamethod #methodparametersjava
#javamethodparameters
#methodcalling #sgtutorial #english #java
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: