This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Implementation of abstract method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Implementation of abstract method" Watch "Implementation of abstract method" New topic
Author

Implementation of abstract method

Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
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 ]

Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Karu Raj
Ranch Hand

Joined: Aug 31, 2005
Posts: 479
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

Joined: Aug 03, 2002
Posts: 7729
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 ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
Thanks for you reply Mr. Barry

Sandy
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Implementation of abstract method
 
Similar Threads
Cannot acces Protected Variable
Please explain this classpath
Java Compiler
what this mean?
Why does this work.