This was the question: Write a java program to implement Inheritance. Order contains details like, order id,
item name, cost, transport charges. Delivery & Schedule are derived from Order.
Delivery consists of address, delivery agent name & contact number. Schedule
contains source, destination, transport type (Air/Road/Water) & expected delivery
date. Display all the details.
What am I doing wrong? I tried a much longer and complicated way with super keyword but it didn't work for me either. I have just started learning Java and even though I understood basic of Inheritance this confuses me(as well as Overriding).
Paul Clapham wrote:
What makes you think you are doing something wrong? Did you get an error message from something? Or did your instructor tell you that you did something wrong? Tell us the details.
I ran this on eclipse, and I get error of initialization at boot level, and state module of previous file to be missing. There are no clear errors pointed out on console and no red markings in the editor either. So in short it is not getting run at all and I don't know where i erred.
You use the "extends" keyword which is how you implement inheritance in Java but I don't see anything in your sub-classes making use of the Order1 super-class.
When you say things out loud (or to yourself) note the nouns and their relation ships. A "Car" IS-A "Vehicle" :: this is an example of inheritance. In your code can you say a "Delivery" IS-AN "Order1" ? Or does that not make sense. How about a "Schedule" IS-AN "Order1" ? Seems a bit suspect to me.
Krina Darwin wrote:I ran this on eclipse, and I get error of initialization at boot level, and state module of previous file to be missing. There are no clear errors pointed out on console and no red markings in the editor either. So in short it is not getting run at all and I don't know where i erred.
This is a problem in Eclipse and nothing to do with Java or inheritance at all. I searched the web for "eclipse initialization at boot level" and the pages I found have a variety of descriptions of the problem. I can't tell which of them applies to your situation. It looks like something to do with the way your Eclipse project is set up -- did you get specific instructions on how to use Eclipse from your instructor?
It is probably quicker to use jshell, which is included with all versions of java® ≥ 9.All I did was write jshell at a terminal (line 1), copy'n'paste all your code onto the terminal, and then instruct the terminal to run the main() method with the instruction HierarchicalInheritance.main(null); (line 57). I am using a Linux box, but the process should be exactly the same on a Mac or Windows®.
I agree with Carey that your example is a poor example of when to use inheritance.
And if it takes twenty years to deliver your goods, even the delivery company ****** can do better than that