I have an abstract class and 2 subclasses. How do you work with them if you cannot instantiate the abstract class. I had written code that initially used a class and subclass and later realised I would be best to have 2 subclasses from the parent class. I understand this is a way of doing multiple inheritance in Java. My existing code was instantiating the parent class and I was
working with that. Now, I cannot instantiate the parent class as the class is now abstract.
Is it only the subclasses I can now instantiate? These are normal classes.
One subclass is employee and has date of birth, salary and the other subclass is customer and has favouritefood, paymentdetails
The parent class is person
Any help would be much appreciated.
You don’t need to instantiate parent class. You have to use it for example for next reason:
You can keep there some general usefull method which you can use (and link to it by the variable of parent class) in you subclasses (also you can override it if you need), for example:
and then you can do so:
PS: abstract class is not for multiple inheritance, multiple inheritance means another thing (class can be inherited from multiple parents)