File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Abstract class" Watch "Abstract class" New topic
Author

Abstract class

Priyanka Chopda
Ranch Hand

Joined: Jul 22, 2003
Posts: 112
interface Animal {
void travel() {}
void feed() {}
}
class Mammal implements Animal {
void travel() {}
)
Except implementing feed() in Mammal, I'm not able to figure out why should I give 'public' access modifier in class Mammal for both methods. Shouldn't it take default A.M i.e 'friendly' from interface?
Also, accroding to my understanding
An abstract class must contain atleast one abstract method.
If atleast one method in a class is abstract the class should be declared as an abstarct class.
please Correct me if I'm wrong!
any comments on this error?
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
First of all, all methods defined in an Interface are implicitly public. Therefore, when you define them in a class that implements that interface, they must be public as well.
Secondly, an abstract class DOES NOT need to have an abstract method. Such a case simply defines a class which can not be instantiated. However, if a class has at least 1 abstract method, the class MUST be defined abstract.
I hope that helps,
Corey


SCJP Tipline, etc.
Priyanka Chopda
Ranch Hand

Joined: Jul 22, 2003
Posts: 112
Thanks Corey!
I was under the impression that if you don't have any modifier specified by deafult it is 'friendly'. I guess it true only for classes and not for interface methods!
Thanks
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Rather than "friendly," most people refer to members without an access modifier as having either "default" or "package" access. I don't think I've ever heard anyone refer to it as "friendly" before.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
"friend" is a C++ thing. "default", "package", or "package-default" are used in Java.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstract class