If we have two public classes in a single java file ,how i have to give the name of the particular java file and how i can compile it?

Showing Answers 1 - 12 of 12 Answers

SailajaT

  • Nov 14th, 2005
 

As per the Java convention and guide lines every class declared as public must be defined individually in a single file. If we have two public classes then we need to have to separate files for them. We can not put them in a single Java file. If you try to put also, you will see syntax error.

  Was this answer useful?  Yes

Pranay Goyal

  • Nov 24th, 2005
 

You cannot create more than one public class in a single file since each public class requirs a separate file to be created.

  Was this answer useful?  Yes

smriti

  • Nov 29th, 2005
 

 If we have two public classes in a single java fil...

  Was this answer useful?  Yes

Debasish Dutta Roy

  • Jan 16th, 2006
 

You can surely have 2 public classes in a single physical file. Here one class is the main class and that should be the name of the class and the other is the inner class to the main class. Here is a sample code.public class Second { /** * */ public Second() { super(); inside in = new inside(); in.iamInside(); } public static void main(String args[]){ Second sec = new Second(); } public class inside{ void iamInside(){ System.out.println("I am inside"); } }}

SM@work

  • Feb 17th, 2006
 

If a java class file already have a public method then the other method modifier within the java file can be either final or abstract and not public. Whereas it can take the class without the modifier which already has a public class. And the scope of the other class will be only visible within the same class and not ouside.

  Was this answer useful?  Yes

sandy07

  • Mar 29th, 2007
 



       i think public class in one file are only possible with inner classes we cannot define two public classes separately in a file

  Was this answer useful?  Yes

sampra

  • Feb 15th, 2008
 

servlet congig and servet context bth are java hasmap object serv context obj is static abd accessbale fr all the  config

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions