• 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 classes

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,


Can a top level class be declared as Private.

There is a question in a mock test :


Q16: Which of the following is not a valid top level class?

a). public class topclass

b). static class topclass

c). private class topclass

d). all the above

e). a and b



The answer is given as e.

I think the answer is c.

what do u say.
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think , b & c should be answer .
 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh ya right static can't be declared in a to level class.

Thank you Rathi ji.
 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hold on a inner class marked static is called a top level class .
Then how come b is correct.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun has changed their definition of what a top-levle class is. In the beginning (JLS 1st edition) there was no such thing as a nested class or inner class, and life was simple. Then they released the Inner Classes Specification, which was also called the Nested Classes Specification, and confusion ensued. (Partly because the so-called Inner Classes Specification also covered static nested classes, which is a sign that the people involved were not all in agreement about what they were doing.) On particularly poor decision they made was to introduce the term "top-level nested class" to describe a nested class that was static (and therefore similar to a "true" top-level class, in some ways, but different in others). Fortunately, someone later realized that "top-level nested" was a really stupid and confusing term, and when they wrote the JLS 2nd edition to incorporate nested classes, they changed the terminology a bit, removing the term "top-levell nested class". It's gone now. Good riddance. Unfortunately there are still some books and mock exams which still use the old term - sometimes correctly, sometimes incorrectly. In general, it's not worthwhile to worry about what the "correct" answer is to a question like this (according to the test author). In many cases, the test author is simply wrong.

In this case, using modern (post-JLS2) terminology, a top-level class cannot be declared private, or static. Ever. Anyone who tells you otherwise is using old terminology - ignore them. There is no such thing as a top-level nested class; forget you ever heard the term.
 
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic