Pregunta

I learned that there was a "default" access-modifier , as in "default" being a keyword . However this oracle tutorial doesn't mention any modifier with such a keyword. It only has a no-modifier that acts as a default. Has the "default" keyword deprecated ?

¿Fue útil?

Solución 2

The "default" access modifier is when there is no access modifier given (that is, not one of public, private or protected).

default the keyword is used in the context of a switch statement. It is the "default action" to take if none of the other cases match.

Otros consejos

The default can optionally be used in a switch statement to label a block of statements to be executed if no case matches the specified value. Alternatively, the default keyword can also be used to declare default values in a Java annotation.

Access Levels
Modifier    Class   Package Subclass    World
public  Y   Y   Y   Y
protected   Y   Y   Y   N
no modifier Y   Y   N   N
private Y   N   N   N

There no keyword for default of modifier .That is in different context of switch.

LINK

default is keyword which there for different purpose. Modifiers (like public, private, protected) are part of keywords.

You can't mention default as your access modifier. If you don't mention any access modifier (public, protected or private) then compiler consider it as a default access modifier. where if it is a method you can only access within that package only.

Default keyword is used in switch. that keyword doesn't have any relationship with access modifier

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top