• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

private class MyClass?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hy everybody...
I'm new here and that's my first topic here. =D
I'm starting my studies for SCJP6 this week, with Kathy Sierra & Bert Bathes Study guide.

The kind of Classes that Java support are only public and "default"?
Why can't we have a class just like "private class Myclass" to use in the same source file?

Thanks.
 
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,

A top level class can never be private. If we make it private, nothing could access it. So what is point of writing such a class itself? But, inner classes can be marked private. We can say that they are similar to private members of a class. Private inner class can be accessed only within the scope of top level class in which it is declared.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Fabio Leal wrote:Hy everybody...
Why can't we have a class just like "private class Myclass" to use in the same source file?

Thanks.



There is no "Source File" level scoping.
 
Fabio Leal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well...
My doubt is why is this construction valid:



And this one Invalid:
 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the advantage of declaring a class Private?
 
Fabio Leal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question solved:

"Although all four access controls (which means all three modifiers) work for most
method and variable declarations, a class can be declared with only public or
default access; the other two access control levels don't make sense for a class, as
you'll see."
(SCJP6 Study Guide - Kathy Sierra, Bert Bathes)
 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right! It doesn't make any sense here.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic