• 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

top level private class

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can a top level class be private?
No. If a class was private.. who could use it? For a normal, top-level class, the only access modifiers that makes sense are public and default(package). Only nested inner classes can be private.

I got a little stumbled. I can ofcourse declare a top level class as private. JAVA does not stop me. Common sense does !!!
But how do we comprehend such questions?
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vikash Agarwal:
I can ofcourse declare a top level class as private. JAVA does not stop me.



Wanna bet?
 
Ranch Hand
Posts: 652
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vikas,
You cannot declare top level class as private. You will get compiler a error.



Regards
Nik
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, i guess you could argue that you CAN indeed write a file that declares a top-level class private. however, would you be allowed to run it, or even compile it? would it be VALID java?

try it and find out!
[ June 05, 2007: Message edited by: Fred Rosenberger ]
 
Peter Chase
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Fred Rosenberger:
well, i guess you could argue that you CAN indeed write a file that declares a top-level class private.



... only to the extent that you can argue that I can write a time-travelling program by calling java.util.Date.transportMe(). I can type the source code into an editor, but it won't compile, run or do anything.
[ June 06, 2007: Message edited by: Fred Rosenberger ]
 
Vikash Agarwal
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry guys... actually did not know that it would throw compilation error. I perceived it would compile but in non-usable format.
Thanks for clarifying.
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Peter Chase:
... only to the extent that you can argue that I can write a time-travelling program by calling java.util.Date.transportMe(). I can type the source code into an editor, but it won't compile, run or do anything


I didn't say it was a JAVA file - I just said it was a file. My goal was to get Vikash Agarwal to try it out, and see what happens.
[ June 06, 2007: Message edited by: Fred Rosenberger ]
reply
    Bookmark Topic Watch Topic
  • New Topic