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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the purpose of garbage collection in java, and when is it used?

794


What is the size of int in 64-bit jvm?

782


What is executor memory?

723


Which way a developer should use for creating thread, i.e. Sub classing thread or implementing runnable.

713


What is difference between fileinputstream and filereader in java?

781


What is valid keyword in java?

766


Why null value is used in string?

767


Define class?

722


What are the kinds of polymorphism?

830


What are user defined exceptions?

807


Say you want to store the information about a number of pets in an array. Typical information that you could store for each pet (where relevant) would be • Breed of animal • Animal's name • Its birth date • Its sex • Whether it has been sterilised or not • When it is due for its next inoculation • When it last had its wings clipped For each type of pet (eg. dog, cat or bird) you would typically define a class to hold the relevant data. Note: You do not need to implement these classes. Just answer the following questions. 3.1.1 What would be the advantage of creating a superclass (eg. Pet) and declaring an array of Pet objects over simply using an array of Objects, storing each of the instances of the different pet classes (eg. Dog, Cat or Bird) in it? 3.1.2 Would you define Pet as a class or as an interface? Why? (2) (2)

1573


Can we convert stringbuffer to string?

769


What is exception handling in java?

799


What is the difference between sop and work instruction?

692


How to make a class or a bean serializable?

737