aspose file tools*
The moose likes Mock Exam Errata and the fly likes Marcus Green's Exam #1 Question 59 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Marcus Green Watch "Marcus Green New topic
Author

Marcus Green's Exam #1 Question 59

Kevin Cary
Ranch Hand

Joined: Jan 24, 2001
Posts: 53
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
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
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
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
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
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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Marcus Green's Exam #1 Question 59