Raghavendiran
Answered On : Aug 5th, 2011
Depends on which object u invoke on run time..
when these file containing these classes are compiled, (assuming u have a public class in that file), A.class and Test.class would be created..
then if you enter java A, then main inside A would be executed.. if you enter java Test, then main inside Test would be executed..

4 Users have rated as useful.
Login to rate this answer.
When any java file has more than one class and those classes if have different main() then the class which will be loaded by jvm, will be run and it's main method will be executes. And let you save your program by "a.java"
for your code
1. Javac a.java // will create a.class file and test.class file
now,
for output on console as hi friend... You need to write java a
i.e you have loaded a class and it's main() will execute, now same for test.class .. You need to write java test and it will result in how are you
Login to rate this answer.
it depends on class which you call at run time....
Login to rate this answer.
it will give error.bcoz java is pure OOP language..so everything should in class...
Login to rate this answer.
This peace of code does not give any error, it will decide in run time to which main method will be called based on the object called...
Login to rate this answer.
Suvind Kumar
Answered On : Aug 21st, 2011
It will give error because first u creating a class and after that closed the class and again u create a class with main method.This is invalid. it is possible to create double main method in a program but when the first class will be closed then it will give error at compile time...
Code
class A{
public static void main()
{
System.
out.
println("Hi Friends");
}}
class B extends A
{
public static void main
(String [] ar
)
{
main();
System.
out.
println("How r u?");
}
B b=new B();
}
Login to rate this answer.
Pravin Kumar
Answered On : Aug 21st, 2011
only one main method is called ((public static void main(String []ar)) and remaining main method will be called by main method ... Ex....
Code
class A{
public static void main()
{
System.out.println("Hi Freiends");
}}
class B extends A
{
public static void main(String [] ar)
{
main();
System.out.println("How r u?");
}
B b=new B();
}
Login to rate this answer.
Class A will execute first
Login to rate this answer.
SHIVA
Answered On : Sep 3rd, 2011
By the priority, level method will be executed.
Login to rate this answer.
It depends which class file main method you invoked.
because two separate class file generate as soon as it is compiled by the JVM.
Login to rate this answer.
venkat
Answered On : Sep 12th, 2011
output is hi friend
Code
class A
{
public static void main
(String args
[])
{
System.
out.
println("hi friend");
}
}
class Test
{
public static void main
(String args
[])
{
System.
out.
println("how are you");
}
}
Login to rate this answer.
At run time it will ask that which method do you want to run
Login to rate this answer.
teena hadpawata
Answered On : Jun 11th, 2012
Hi friend will be the output
Login to rate this answer.
Rashmi Ahuja
Answered On : Jun 16th, 2012
when we execute this class with class B then it first call to class A method main which is like normal method. after that B class print msg is printed
Login to rate this answer.
Manas Naik
Answered On : Jul 7th, 2012
When we compile it create two different class with name a.class and test.class .so,according to your call it will execute.
Example--java test
then output is "how are you" only not hi friend
Login to rate this answer.