private, protected Access Modifiers with a class

Why cant we use private and protected access modifiers with a class?

Thanks.

[89 byte] By [beejuma] at [2007-11-27 10:11:14]
# 1

I think that you can.... for inner classes.

petes1234a at 2007-7-28 15:11:53 > top of Java-index,Java Essentials,Java Programming...
# 2

Yes we can use it with inner classes, but how about using them outer classes. Y cant we do so?

beejuma at 2007-7-28 15:11:53 > top of Java-index,Java Essentials,Java Programming...
# 3

You want a class to have two different access modifiers?

Care to explain how that is supposed to work.

floundera at 2007-7-28 15:11:53 > top of Java-index,Java Essentials,Java Programming...
# 4

I dont want a class to have two access modifiers at a time. It's this way what I want.

private class Sample{}

( or)

protected class Sample{}

beejuma at 2007-7-28 15:11:53 > top of Java-index,Java Essentials,Java Programming...
# 5

Top level calsses can only have public or default access (BTW, I can't think of a reason to use protected or private... can you ?)

The access modifiers protected and private pertain only to member classes (as already mentionned above.)

TimTheEnchantora at 2007-7-28 15:11:53 > top of Java-index,Java Essentials,Java Programming...
# 6

a class can not be private if we declare like that the error will be modifier private not allowed here. So the outer class can't be declared as private.

Yannixa at 2007-7-28 15:11:53 > top of Java-index,Java Essentials,Java Programming...
# 7

Private means "only accessible in the defining class." What's the defining class in a top-level class? There is none. Private would be meaningless.

And if you could have a top-level private class, how would you ever use it?

jverda at 2007-7-28 15:11:53 > top of Java-index,Java Essentials,Java Programming...