This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I remember that each source file must have a public top level class yet the below example works. How is this possible? class Base{ private void amethod(int iBase){ System.out.println("Base.amethod"); } } class Over extends Base{ public static void main(String argv[]){ Over o = new Over(); int iBase=0; o.amethod(iBase); } public void amethod(int iOver){ System.out.println("Over.amethod"); } }
Manfred Leonhardt
Ranch Hand
Joined: Jan 09, 2001
Posts: 1492
posted
0
Hi, Your memory is failing you ... The correct quote is:
A Java source file can contain AT MOST one public top level class.
Therefore even an empty file is a valid Java source file. Regards, Manfred.
Kevin Cary
Ranch Hand
Joined: Jan 24, 2001
Posts: 53
posted
0
Thanks for your help Manfred. This certainly clears my confusion. Kevin
Originally posted by Manfred Leonhardt: Hi, Your memory is failing you ... The correct quote is:
A Java source file can contain AT MOST one public top level class.
Therefore even an empty file is a valid Java source file. Regards, Manfred.
sandeep bagati
Ranch Hand
Joined: Feb 22, 2001
Posts: 62
posted
0
hi kevin The question is perfectly right and answer too. The Top-Level classes can be public or can have a default modifier.
Originally posted by Kevin Cary: I remember that each source file must have a public top level class yet the below example works. How is this possible? class Base{ private void amethod(int iBase){ System.out.println("Base.amethod"); } } class Over extends Base{ public static void main(String argv[]){ Over o = new Over(); int iBase=0; o.amethod(iBase); } public void amethod(int iOver){ System.out.println("Over.amethod"); } }
Kevin Cary
Ranch Hand
Joined: Jan 24, 2001
Posts: 53
posted
0
Hi Sandeep, I your message seems to say a top level class can be public or default. For clarification, I think a top level class can have the attributes, public, protected, or default but not private. Is this correct? Kevin propoise95117@yahoo.com
Originally posted by sandeep bagati: hi kevin The question is perfectly right and answer too. The Top-Level classes can be public or can have a default modifier.
Kevin Cary
Ranch Hand
Joined: Jan 24, 2001
Posts: 53
posted
0
Sorry about this last post. The mistake is mine. A top level class can either public or default. Kevin
Originally posted by Kevin Cary: Hi Sandeep, I your message seems to say a top level class can be public or default. For clarification, I think a top level class can have the attributes, public, protected, or default but not private. Is this correct? Kevin propoise95117@yahoo.com