Why non nested classes in java are not having marked as
protected access specifier

Answer Posted / udita bose

Sorry, but previous answer by Yayati Pavan does not answer the question. If that answer is true then there should not be a problem with a "protected" class, as "protected" keyword is wider than default one.

There are no protected class because it is unnecessary to have them. Access modifiers for classes determine 2 things

i) If a class can create instance of other class ?
ii)If a class can extend other class ?

Now, any class within the same package will be able to create an instance of "protected" class - this is true for default-accessor and public classes. No class outside the package will be able to create an instance of "protected" class - this holds good for default-accessor classes.

Again, for a "protected" class by its definition will be extendible by any class within its package - so is default-accessor class, and extendible for any class outside its package - so are all public classes.

Both of this reason nullifies the reason for a protected class.

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can I override protected method in java?

600


What is package private scope in java?

537


What are the different approaches to implement a function to generate a random number?

573


What is api in java?

543


What is tcp and udp?

607






Explain the scope of a variable.

640


Explain the available thread states in a high-level?

530


Explain covariant method overriding in java.

544


Can we define private and protected modifiers for variables in interfaces?

584


What is the main function in java?

533


What is Hierarchy of exception?

649


How to make a read-only class in java?

595


Can we synchronize static methods in java?

600


Is there any way to skip finally block of exception even if some exception occurs in the exception block?

602


What is integer size in java?

514