The combination of access modifiers such as abstract and protected are invalid combinations. If invalid please explain...
Please answer ASAP.
Thanks & Regards
M.Satyanvesh
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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?Class can only be public or default.
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
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.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?
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
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)
snowguy13 (February 1st, 2012)
Only public, private and protected keywords are access modifiers while there are four different access levels including three keywords and default access level.Ah, okay. Thank you.
Is "protected" an access modifier, or is it categorized as a non-access modifier?
snowguy13 (February 1st, 2012)
Hmm... I think it's a little bit odd that "protected" allows for more access than default!
But thanks both of you for the help!
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
This is not entirely true. What about the following?A class can only have public or default access modifier
public class OuterClass{ public class PublicInnerClass{ } private class PrivateInnerClass{ } protected class ProtectedInnerClass{ } }
Last edited by copeg; February 1st, 2012 at 03:13 PM.
"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, ..