By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,791 Members | 1,314 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,791 IT Pros & Developers. It's quick & easy.

is it possible java can have two main(),1st is super class 2nd is subclass fasion?

P: 1
.................................................. .................................................. ..................
Feb 10 '12 #1
Share this Question
Share on Google+
1 Reply


P: 21
Hi,

Yes, It is possible. JVM only find the main class of saved file name.
for example:

class A{

public static void main(String args[]){
A a=new A();
System.out.println("A");
}
}
class B extends A{
public static void main(String args[]){
B b=new B();
System.out.println("B");
}
}
If this program will save by name A.java then main method of class A will get call. or if saved as B.java then B class main();
Feb 10 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.