Alex Rivera | Logout

Why are protected members allowed in final java classes?

Asked 2010-09-07T17:54:21.367
20

Why are protected members allowed in final classes?

Shouldn't this be a compile-time error?

Edit: as people have pointed out, you can get same package access by using the default modifier instead. It should behave in exactly the same manner, because protected is just default + sub-classes, and the final modifier explicitly denies subclassing, so I think the answer is more than just to provide same package access.

Edit
Report

2 Answers

16

Because protected members can be accessed by other classes in the same package, as well as subclasses.

answered 2010-09-07T17:57:24.113
0

You can argue that, but there's no real harm anyway. A non-final class may also have a protected member, but no subclass, it won't bother anybody either.

answered 2010-09-07T18:09:19.857

Your Answer