• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Called abstract class methods from another class returns null value

 
Ranch Hand
Posts: 114
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the problem
I have a one abstract class named MovingObject.java and I want to call some of methods in abstract class. I have written one class named MyMovingObject.java which extends from abstract class and I have written constructors to override super-class constructors. I guess Now the subclass will contain all the superclass methods with defined methods init. Then I have created one more class named Simulator.java and this class extends from MyMovingObject.java and I have created object to MyMovingObject class but when I am calling methods from abstract class, I am getting null as a returned values for all methods,I want to call routePlan() method in MovingObject.java
these are the programs

this is the I have written one class which extends from abstract class


Now I have written one more class which extends MyMovingObject.java and this is the code I have written
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't even say what the problem is, where it is, or anything. You can't expect someone to dig through a thousand lines+ of code and GUESS what your issues are.

Did you test any of the code first? Can't you reduce the issue to a *small* usecase that's possible to understand *easily*?
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes David I changed the code and mentioned clearly what is the problem have
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you suppose it to return something else when you never call setRoutePlan ?
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply I tried with that option also but giving errors in that setRoutePlan() method we need to pass something ,Here I tried with pasing same arguments and got the error, and I am confused what else I need to pass setRoutePlan() method when I am calling
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how about a Route object ?
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Route object will have one constructor and some methods init
here is the code
Route.java
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So how does that solve anything. setRoute takes a Route object. So pass a Route object, and routePlan won't return null.
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ofcourse you are right I passes the Route Object like this correct me if I am wrong
mo.setRoutePlan(Route rt);

got the compilation Error
Error
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you did not understand the whole concept of object creation.

Check out a general java tutorial.

This is the way it would work

 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its returning zero for route and routePlan when I passed different values

Output
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't really understand what you are saying ??
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
by passing value 1 while creating object to Route class is the size of the ArrayList right? I ran the code and got zero as a output.But it will return list of objects(that is actually RoutePlan-RoutePLan will have list of motionless Objects) ,but its not returning expected value and what might be the solution to get expected output..
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change what you're printing?
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I didn't get you David
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pretend you're the computer. Trace through the execution line by line.

Try posting what you think is happening; it should be an ordered list of steps from where you start executing until the end. Post the *exact* code that you believe is being executed by the steps you list. When you run the program, see if the code you believe is being executed is actually executed. If there's a discrepancy between what is happening and you *think* should be happening, try to figure out why.

Remember: we don't have your computer in front of us. It's difficult to figure out what *is* happening vs. what *should* be happening and compare both to your expectations. If you have to, post the entire code again, and maybe somebody will copy it in to their IDE and see if we can point you in the right direction.
 
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic