Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract/concrete methods and modifiers

 
Damien Howard
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that certain modifiers can not be applied to abstract methods such as synchronized or native.
What about the concrete methods that imjplement the abstract methods? Can these use the modifiers?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the JLS, §8.4.3 Method Modifiers. It has all of the information you want and then some.
 
Damien Howard
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems then that a concrete implementation of an abstract method could never be synchronized or written in a native language then.
Is that correct?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Damien Howard:
It seems then that a concrete implementation of an abstract method could never be synchronized or written in a native language then.
Is that correct?

Where did you find that in the JLS? An abstract method can't be native but the implementation of an abstract method can be.
 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Damien Howard:
I know that certain modifiers can not be applied to abstract methods such as synchronized or native.
What about the concrete methods that imjplement the abstract methods? Can these use the modifiers?

I think any modifier can be applied to concrete method as it is not abstract anymore.Correct me if I am wrong.
Veena
 
rahul V kumar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you mean this,
abstract class A
{
abstract void aMethod();
}
class B extends A
{
synchronized void aMethod(){ }
//native void aMethod();
public static void main(String[] arg)
{
}
}

then this code compiles without any issues.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic