Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

I wrote this code for Hierarchical Inheritance and it is not working.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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).
 
Sheriff
Posts: 26950
83
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Krina, welcome to the Ranch!

Krina Darwin wrote:What am I doing wrong?



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.
 
Krina Darwin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Saloon Keeper
Posts: 8920
76
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 26950
83
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Carey Brown
Saloon Keeper
Posts: 8920
76
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you put all that code in a single .java file like you posted here, then you need to make the class that contains the main() method public.
 
Carey Brown
Saloon Keeper
Posts: 8920
76
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And the name of the file MUST be HierarchicalInheritance.java with the correct character cases.
 
Saloon Keeper
Posts: 13481
304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Error messages that start with "Error occurred during initialization of boot layer" are related to Java modules.

Please copy and paste the EXACT error message here. Also share your module-info.java file with us, if you have one.
 
Marshal
Posts: 74637
335
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch (again)

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic