Lesson 6 :- Calling a method
A method is a collection of statements that are grouped together to perform an operation.
A method executes when it is called.
Try below example & understand what is calling a method.
public class New{
public static void main(String[] args){
System.out.println("This is the main method.");
display();
System.out.println("End of the main method.");
}
public static void display(){
System.out.println("This is the display method.");
}
}
If we write something under the main method , only those will execute. It means, we need to add all the things what we want to execute, under the main method. It is very basic theory in java programming language.
A method executes when it is called.
Try below example & understand what is calling a method.
public class New{
public static void main(String[] args){
System.out.println("This is the main method.");
display();
System.out.println("End of the main method.");
}
public static void display(){
System.out.println("This is the display method.");
}
}
If we write something under the main method , only those will execute. It means, we need to add all the things what we want to execute, under the main method. It is very basic theory in java programming language.
Comments
Post a Comment