2

I know why private and protected are illegal modifiers for a class but why is default not acceptable. I think if we don't specify any access modifier, default gets assigned. But typing it explicitly like default class Student gives me a syntax error

mjn
  • 36,362
  • 28
  • 176
  • 378
Manoj
  • 644
  • 12
  • 21
  • There is no such access level as "default". An access level is one of these four: "public", "private", "protected", or "package-private". The last one is not a keyword, and can only be specified as the absence of a modifier. Which access is the default (when there is no modifier) depends on what the thing is and where it is; usually it's package-private, but members of interfaces are public by default, and enum constructors are private by default. – Boann Oct 18 '16 at 00:58

2 Answers2

3

The default access modifier in Java can be used by just omitting any access modifier. Java 8 introduced a new default keyword used to provide a default implementation for an interface's method but, despite its confusing name and location in the method's declaration, it has nothing to do with access modifiers.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
1

A class may be declared with the modifier public, and 'nomodifier' but not the meaning of instead of nomodifier 'default' key word

please go through this link https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

Chandu D
  • 505
  • 3
  • 17
  • But Java has provided `default` as a keyword. Where is it used except in default methods of interface – Manoj Jun 10 '16 at 09:02
  • @Manoj The only other use of the `default` keyword is in the [`switch` statement](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html). – Boann Oct 18 '16 at 00:57