What is the order of execution of all user defined methods
0
01.Java Basics.
What is the order of execution of all user defined methods?
In the order they are called from main method or from any one of the method calling from main method.
// Example.java
class Example
{
static void m1()
{
System.out.println("m1");
}
static void m2()
{
System.out.println("m2");
}
public static void main(String[] args)
{
System.out.println("main");
m1();
}
}
OutPut:
>javac Example.java
>java Example
main
m1
// Example2.java
class Example2
{
static void m1()
{
System.out.println("m1");
m2();
}
static void m2()
{
System.out.println("m2");
}
public static void main(String[] args)
{
System.out.println("main");
m1();
}
}
OutPut:
>javac Example2.java
>java Example2
main
m1
m2
//Example3.java
public class Example3
{
public static void main(String[] args)
{
System.out.println("main");
m1();
}
static void m1()
{
System.out.println("m1");
m2();
}
static void m2()
{
System.out.println("m2");
}
static void m3()
{
System.out.println("m3");
}
}
O/P:
>javac Example3.java
>java Example3
main
m1
m2
Previous | 1 | 2 | 3 | 4 | 5 | Next |
0 comments: