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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / yayati pavan

When the non nested class declared as public or
default(public) the jvm can access the class and execute.
So non nested class must always public. other wise jvm can't
access the class.

Is This Answer Correct ?    7 Yes 9 No

Post New Answer

More Core Java Interview Questions

Difference between Linked list and Queue?

0 Answers   Virtusa,


What is the full form of jpeg?

0 Answers  


What are nested classes in java?

0 Answers  


How do you define a singleton class?

0 Answers  


Where we write javascript code in html page?

0 Answers  


Which is the best sorting technique in java?

0 Answers  


What is lossy conversion in java?

0 Answers  


What is currentthread()?

0 Answers  


What is sortedmap interface?

0 Answers  


Addition to previous section relative word 5th one was Putrid ans: rotten, also there was prob. in 1st section on bucket weight ans:10kg, also there was a prob. on train speed to find bridge length ans:800 mtrs.

0 Answers   V2 Solutions,


what is difference between prepare stetement and callable starement with example?

1 Answers   CMC,


Can we overload run() method in java?

0 Answers  


Categories