Link to home
Start Free TrialLog in
Avatar of ksfok
ksfok

asked on

Java OOP Extending Classes and Inheritance

Given an abstract ItemBase class, two subclasses A and B are extended from it with methods specific to each one.  For example:

ItemBase has generic method V, W
subclass A has specfic method X
subclass B has specfic method Y

How can the above design be implemented so that ItemBase be used as an Array that contains objects of A or B calling their individual method X or Y? Can methods X and Y be omitted in Itembase or should they be defined in it? How?
Thanks for any help.
ASKER CERTIFIED SOLUTION
Avatar of Venabili
Venabili
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ksfok
ksfok

ASKER

  1. Make a method someMethod in ItemBase and make it abstract
  2. Then implement it in A and B instead of implementing differently named methods. And make this implementation call the individual X and Y methods
Please kindly provide code syntax for the above.
Thanks much.