Hi I am pretty much a greenhorn and just about got started preparing for the certification exam. I need a clarification. According to RHE there can 'generally' be only one top level public class. Are there any exceptions? ------------------ Bos Indicus
Bos Indicus
Jane Griscti
Ranch Hand
Joined: Aug 30, 2000
Posts: 3141
posted
0
Hi Kumar, A source file can contain more than one top level class but only one top level class can be declared public. (A top level class is not enclosed within the declaration of another class). For example, <code> public class TopOne {} class TopTwo {} class TopThree {} </code> The above declarations can all appear in one source file. The file must be saved as <code>TopOne.java</code> (it has to match the name of the public top level class). However, the following source file would produce a compile error: <code> public class TopOne {} public class TopTwo {} class TopThree {} </code> as it declares more than one public top level class. Hope that helps.