• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Marcus Green's Exam #1 Question 59

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
}
}
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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, coderanch, protected, or default but not private. Is this correct?
Kevin
[email protected]

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
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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, coderanch, protected, or default but not private. Is this correct?
Kevin
[email protected]


 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic