The combination of access modifiers such as abstract and protected are invalid combinations. If invalid please explain...
Please answer ASAP.
Thanks & Regards
M.Satyanvesh
Printable View
The combination of access modifiers such as abstract and protected are invalid combinations. If invalid please explain...
Please answer ASAP.
Thanks & Regards
M.Satyanvesh
Class can only be public or default.
And instance methods can be abstract and protected though. But you must need to implement this protected method in the very next concrete class(non abstract) or they will get private and will not be seen by any other hierarchy. So, this combination is valid.
Wait... I thought a class could be declared abstract, too. I also thought that if a class contained an abstract method, it must be declared abstract. Am I thinking of the wrong idea?Quote:
Class can only be public or default.
There is the difference between access and non-access modifiers. A class can only have public or default access modifier while abstract, final, native etc are non access modifiers. So, yes a class can be declared abstract too.
I guess these things are like to known by any java developer, a class having an abstract instance method is of course abstract class.Quote:
I also thought that if a class contained an abstract method, it must be declared abstract
Ah, okay. Thank you.
Is "protected" an access modifier, or is it categorized as a non-access modifier?
protected is an access modifier, because it modifies how the method/variable can be accessed. abstract is not a access modifier, because it doesn't affect access:
Controlling Access to Members of a Class (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
Only public, private and protected keywords are access modifiers while there are four different access levels including three keywords and default access level.Quote:
Ah, okay. Thank you.
Is "protected" an access modifier, or is it categorized as a non-access modifier?
Hmm... I think it's a little bit odd that "protected" allows for more access than default! :P
But thanks both of you for the help!
This is not entirely true. What about the following?Quote:
A class can only have public or default access modifier
Code java:public class OuterClass{ public class PublicInnerClass{ } private class PrivateInnerClass{ } protected class ProtectedInnerClass{ } }
"A class can only have public or default access modifier"
This statement is completely true don't mix Class with Inner Class both are completely different, It will confuse others.
As for as question is concerned
Class: this combination is not valid because protected can not be applied to Class(Not inner class) at all.
For methods there is no problem with this combination.
For Inner class again this is not a problem.
Below link could help you in access and non access.
Java Access Modifier
Java Non Access Modifier
A regular inner class just like member of the outer class, like instance variable or methods. So all the modifiers that apply to these will be applied to inner class too like
final, abstract, public, ..