Why default specifier is not allowed to specify for any class member in Java? -


the default access specifier of java class member "default". mean when no specifier has specified before member of class, java takes default implicitly. have ever tried put default specifier explicitly before method or variable in class. try once , see.

class demo{ default string name; // valid??? } 

i wanted know reason behind it?

default keyword has nothing access modifiers.

in access modifier's context, absence of specific access modifier called default.

default keyword's actual usage -

  1. the default keyword can optionally used in switch statement label block of statements executed if no case matches specified value; see switch.

  2. the default keyword can used declare default values in java annotation.

  3. from java 8 onwards, default keyword used specify method in interface provides default implementation of optional method.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -