Why does java not allow multiple public classes in a java file ?

Answers were Sorted based on User's Feedback



Why does java not allow multiple public classes in a java file ?..

Answer / sushila sonare

suppose in java file so many classes, interfaces, abstract
classes and enumerations are there. we can keep only one of
them as a public because its shown a container and this
container we are keeping all things in our java file.

if we kept public for more then one class then all are that
classes qualified as a container or we are called it
execution unit. again compiler get confuse which container
classes has to kept. So avoiding this confusion multiple
public classes are not allowed in java.

Is This Answer Correct ?    0 Yes 0 No

Why does java not allow multiple public classes in a java file ?..

Answer / rahul

java does not support multiple public classes because of there are only one main method to define......and we can not have multiple main methods in a same class....and we know that java code will always save as the name of class name in which main method are define......

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More Core Java Interview Questions

What we have to do, when we don't want to implement all methods of an interface?

5 Answers  


Explain about object oriented programming and its features?

0 Answers  


Give an example of use of pointers in java class.

0 Answers  


What is a dynamic array java?

0 Answers  


What is the difference between inheritance and encapsulation?

0 Answers  






How do you do a line break in java?

0 Answers  


What is the size of string?

0 Answers  


I need some details about an employee. i have only the employee id in my presentation layer(JSP).I entered that ID and click "Show Details" Button. Question is how the JSP pass that id to Controller layer and DAO and what mechanism we are using to retrive data from DB and how the data passed to JSP as a Output. Please explain in detail.

1 Answers   TCS,


I have a String s = java; What is the output when I say s.replaceAll('j', 'k'); Also what is the value of s after replacing?

8 Answers   KPIT,


What are reference variables in java?

0 Answers  


What state does a thread enter when it terminates its processing in java programming?

0 Answers  


Life Cycle of Thread

4 Answers   IBM,


Categories