• Post Reply Bookmark Topic Watch Topic
  • New Topic

Abstract methods in an abstract class  RSS feed

 
Jason Attin
Ranch Hand
Posts: 234
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, I just wanted to clarify something please.
In an abstract class if I create an abstract method I know it can't be private, but can it be protected or package private (in addition to public of course)?
thanks
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it? It just takes a few seconds...

Henry
 
Jason Attin
Ranch Hand
Posts: 234
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eh eh, sorry it didn't occur to me to try as I read something on one of the questions, so I thought I'd post here to make sure whether that was the case or not.
Anyway, this seems to compile OK

so abstract methods don't have to be only public :-)!
thanks
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lat's see what the Java® Language Specification (=JLS) says. Beware: the JLS can be difficult to read. Wind up a bit and we see:-
It is a compile-time error if a method declaration that contains the keyword abstract also contains any one of the keywords private, static, final, native, strictfp, or synchronized.
You can't call it private because that means it cannot exist in a subclass. You cannot call it static because it is supposed to be overridden as an instance method, so it can't be static. You can't say final because that prevents overriding. You can't say native strictfp or synchronized because that implies the method has already been implemented.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!