• Post Reply Bookmark Topic Watch Topic
  • New Topic

Implementing abstract methods in the concrete subclass  RSS feed

 
Deepa Guha
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
While implementing abstract methods in the first concrete subclass, should the overriding priciples be used?.
For example, I found the following code working though I was under the understanding that the signature of the implementing method in the subclass should be the same as that of the Abstract class.
The method has been marked synchronized in the subclass.
Can someone explain this ?
abstract class mytest70{
public abstract void getFireStation();
}
public class mytest71 extends mytest70{
public synchronized void getFireStation()
{
System.out.println("Fire....");
}
public static void main(String[] args){
mytest71 m = new mytest71();
m.getFireStation();
}
}
Thanks!!
 
Narasimha Rao B.
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deepa,
See my in-line comments..
While implementing abstract methods in the first concrete subclass, should the overriding priciples be used?.
>> Yes you should follow overriding priciples.
For example, I found the following code working though I was under the understanding that the signature of the implementing method in the subclass should be the same as that of the Abstract class.
The method has been marked synchronized in the subclass.
>> Declaring the method as synchronized or not will not come under method signature. Hence the overriding method can be declared as synchronized. It is at the discretion of the sub class to declare its methods are synchronized or not.
Hope this helps, if not come with more doubts..
 
Deepa Guha
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
This means that non-access modifiers can be added to the subclass method signature.These would include strictfp,synchronized,static,final etc..
This is correct?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!