• Post Reply Bookmark Topic Watch Topic
  • New Topic

Defenition of Top-level class not consistent  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I noticed that the definition of a top-level class is inconsistent in two of the answers in the Round up game.
The first answer says that top-level classes only can be public, which is fine with me.
The other answer says that there can be several top-level classes in one source file as long as there is only one public top-level class - what will the other top-level classes be then ?!?
Which one of them is right, can a top-level class be anything else than public - and if that's the case for what use?
Thanks in advance ..
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dudli the Dude:
I noticed that the definition of a top-level class is inconsistent in two of the answers in the Round up game.

Which questions? Could you pl. give the question numbers?

The first answer says that top-level classes only can be public, which is fine with me.

They can be public or may have default scope (package), in which case they do not have any access modifier, so only modifier that can be applied to a top level class is public. Does the answer specifically say that they can only be public?

The other answer says that there can be several top-level classes in one source file as long as there is only one public top-level class - what will the other top-level classes be then ?!?

The other top-level classes in the file will have default (package) scope.

Which one of them is right, can a top-level class be anything else than public - and if that's the case for what use?

The second one, if first one is phrased as you say .
As said earlier, they can have default package scope. If file is part of any pakage, all the classes in that package can access each other while public class is the only class which can be accesed by the outside world. There could be more than one file in a package. If there is no package mentioned, all the classes in that file can accesss each other while public class is the only class which can be accesed by the outside world.
The usages are plenty. If there's no reason for a class to interact with the outside world and if it needs to be used only by its package members, it better be non-public i.e. default package level class.
HTH,
- Manish
p.s. I hope, I can answer this though I am not a moderator. Regarding correction in wording of the answer in round up game, someone will answer it soon.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there is REALLY a question that says that top-level classes only can be public, and you can get us the question number, we can tweak the wording to be more correct.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a copy of the questions. It's #18 and the wording is correct, it states: A top-level class can ONLY be marked public or default (package).
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,
I tried to run the game to see the question no but the one that I fought would be incorrect isn't, or the same question exist with diffrent numbers - #18 is the one I found today.
The answer was very clear to - so either someone changed it by now or I must been very sleepy yesterday.. it's a little bit strange though because I checked it twice with a friend before I sent this mail - but sometimes even two people are fooled of their own eyes (they who worked with XP nows that .
Sorry for wasting your time !!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!