Java Child - Parent ? Please help im lost !

[b][red]This message was edited by Mr_Smith at 2002-10-21 9:2:50[/red][/b][hr]
Hi i have a class say Engine and it has a Parent Car how can i use a callback to tell the Car the Engine is broken rather than asking it every 5 seconds?

Ive tried everything and just cant understand callbacks in java.


Comments

  • [b][red]This message was edited by chamster at 2002-10-21 15:51:0[/red][/b][hr]
    I'm not sure if it's what you're looking for but you might send the parent as a pointer to the object. Something like:

    [code]
    class Child
    {
    private Parent parent;

    public Child (Parent p)
    {
    this.parent = p;
    }
    }
    [/code]

    Now, if you have a method [blue]notify ()[/blue] in Parent class you only need to go [blue]this.parent.notify ();[/blue] form Child-class.



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    [email protected]
    http://konrads.webbsida.com



  • [b][red]This message was edited by Mr_Smith at 2002-10-22 3:15:29[/red][/b][hr]
    Help class parent not found so no work
  • Great. Let me know when you're done if it really was what you were looking for.


    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    [email protected]
    http://konrads.webbsida.com

  • help class Parent not found
  • Have you compiled both Parent and Child? Meaning in your case have you compiled Engine and Car?

    Make sure that the .class-files are in your directory (Car.class and Engine.class must be in the directory from which you execute the program).

    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    [email protected]
    http://konrads.webbsida.com

  • [b][red]This message was edited by Mr_Smith at 2002-10-23 6:47:35[/red][/b][hr]
    Yep its all fine and is amazing thx

    bit of confusion back there as i thought u meant there was an actual parent class maybe that acted as a pointer, but i understand how it works now.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories