Thursday 26 April 2018

What is Method, calling a Method & execution of Method?

What is Method, calling a Method & execution of Method?

What is Method?

It is a group of reusable code or statement which can be called from any where in the program .
A method eliminate need of writing a group of code again & again.
“Set of method in known as a program.”
A single method can also be treated as a program.
Without method a program can’t be develop.

Define Method:

As we know in a program method is responsible to perform the task, because it contains statement or commands which will be executed in order to perform the task but we need to define method in the program a method must have a name as well as return type & at least a statement this process is called “defining a method”.

Return type method_name()

Calling a method:

this is also called invoking a method Must be called in order to execute that method.
A method can be called by another method those method that are responsible to called a method are known as caller method.

Execution of Method:

The process in which a method start execution & statement written in side the method are executed one by one.
when last statement of the methods completes execution then execution of method terminate.

Class AA
Static void M1() {
System.console.writeLine(“M1 begins”);
System.console.writeLine(“m1 ends”);
Static void M2() {
System.console.writeLine(“M2 begins”);
System.console.writeLine(“M2 Ends”);
Static void M3() {
System.console.writeLine(“M3 begins”);
System.console.writeLine(“M3 ends”);
Static void main() {
System.console.writeLine(“Main begins”);
System.console.writeLine(“Main Ends”);

No comments:

Post a Comment

Popular Posts