• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Abstract class

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Priyanka Chopda
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"friend" is a C++ thing. "default", "package", or "package-default" are used in Java.
 
reply
    Bookmark Topic Watch Topic
  • New Topic