• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementation of abstract method

 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a small confusion regarding implementation of an abstract method, if the abstract class is in different package then implementing package.

Consider the following code:

-------------------------------------------------------


In the classa I have intentionally kept the default access for method().

Now classa.java compiles clean. Whereas compiling test43.java results in compiler error:
-------------------------------------
test43.java:3: b.test43 is not abstract and does not override abstract method method() in a.classa
public class test43 extends a.classa
^
1 error
-------------------------------------

So I think that if a method has default access in an abstract class then that abstract class cannot have its implementatin outside the package.

I want to know whether I am right or is there any sneaky way to do this?

It seems to be a silly question. But help would be highly appriciated.

Thanx

Sandy
[ September 18, 2005: Message edited by: Barry Gaunt ]
 
Karu Raj
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I think i may be wrong .

but as per my knowledge it is ..

as the method is default this means any other method can overide it only if it is in same package.

correct me if i am wrong.... please
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if a method has default access in an abstract class then that abstract class cannot have its implementatin outside the package.


Correct. Forget "sneaky methods" they will kick you in the butt in the long run.

Making your abstract method protected will allow the subclass to compile.
[ September 18, 2005: Message edited by: Barry Gaunt ]
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for you reply Mr. Barry

Sandy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic