Manoj Manoj - 5 months ago 23
Java Question

Why can't we specify default access modifier for a class

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

Answer

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.