aspose file tools
The moose likes Java in General and the fly likes Abstract Classes / Methods Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Abstract Classes / Methods" Watch "Abstract Classes / Methods" New topic
Author

Abstract Classes / Methods

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 712
Hi, I have a class AAA(abstract), with an abstract method method1().
Class BBB(abstract) extends AAA, but does not contain method1().
Classes CCC1,CCC2(both concrete) extends BBB, and implements method1().

This is shown here

This actually works, but as you can see method1() does not appear in BBB.
I guess the point is method1() is being implemented by in a subclass of AAA, its just not a direct subclass, but a sub-subclass.

Is this a bad thing to do, implementing behaviours for methods declared at the top of a hierachy, at the bottom?

Also, I think this only works because BBB is abstract, and if it were not, then it must implement method1().

Any thoughts? Thanks
greg buela
Ranch Hand

Joined: Sep 04, 2007
Posts: 71
You are right about why it works.
I see nothing wrong with doing it, it's a matter of your model desing, you may have a case where such desing is the right thing.


SCJP 1.5
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3011
    
    9
Consider an exampleMost animals make a sound so it is reasonable to have the makeSound method declared in the Animal class. A mammal doesn't make a specific sound, so there is no need to override the makeSound method in the Mammal class. Dogs and pigs have specific sounds so you implement the makeSound method in those classes.


Joanne
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 712
Thanks good example, that clears it up well.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Abstract Classes / Methods
 
Similar Threads
Abstract inner class
Abstract
override static method
HF EJB, question about page 86
Objects (please can someone clear this up)