Methods is he collection of statements to perform an operation. Methods contain the collection of statements and it is used to perform any task that related to the program.
Method reduces the complexity of the program. For example method reduces the complexity of the program.For example method likes the capsule whenever we need we can call the method to the respective position.
Method can be called with the help of the object. Methods contain different return type such as int, byte,short , long, float, double , string , char and boolean. If the method contain the void return type it will not return anything.
If we used other return type rather than the void we need to return something for example,
We can able to pass the value to the method by the help of arguments that is called the parametrized method. It contain the arguments for example.
This are the various formats and uses of the method in java. well here we are going to call the method in the main method with the help of object.
Method reduces the complexity of the program. For example method reduces the complexity of the program.For example method likes the capsule whenever we need we can call the method to the respective position.
Method can be called with the help of the object. Methods contain different return type such as int, byte,short , long, float, double , string , char and boolean. If the method contain the void return type it will not return anything.
Syntax:
return_type method_name(arguments)
{
//statements
}
This is the basic syntax of the method in java for example
Void method1()
{
system.out.println(Hello Tony);
}
If we used other return type rather than the void we need to return something for example,
int method1()
{
system.out.println(Hello Tony);
return 0;
}
int method1(int a )
{
system.out.println(a);
return (0);
}
public class TONY {
void a();
{
system.out.println(hi);
}
int n(int e)
{
system.out.println(e)
return 0;
}
public static void main (String args[])
{
TONY obj=new TONY();
obj.a();
obj.n(4);
}
}
No comments:
Post a Comment