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.

Re: about access modifiers (abstract and protected)

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.

Re: about access modifiers (abstract and protected)

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?

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 also thought that if a class contained an abstract method, it must be declared abstract

I guess these things are like to known by any java developer, a class having an abstract instance method is of course abstract class.

Re: about access modifiers (abstract and protected)

Originally Posted by snowguy13

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!

Well, both work same except when it comes to the different packages. protected works in different packages only if there is inheritance while default doesn't. And in remaining all cases both work exactly similar.

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, ..

Re: about access modifiers (abstract and protected)

Well, i was supposed to talk about non-nested or non-inner classes. Well, thanks copeg anyways for pointing this out as well. Now, Any non-nested or non-inner class can have only public or default access. This seems fine now.