Results 1 to 4 of 4
  1. #1
    Saletra is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default Method, returning reference to an object

    Hello,

    I want to call a method and gain reference to proper object. Next I wan't to use this reference to running other methods.
    Java Code:
    Kasa [B]myobject;[/B]
    Kasa [B]myobject2;[/B]
    public void run(){
    wybierz();
    [B]result[/B].dodaj(this, priorytet); //reference from wybierz();
    }
    public Kasa wybierz()
    {
    if(1 == 2){
    
    result = [U]myobject;[/U]  //REFERENCE TO OBJECT 
    }else {
    
    Kasa myobject2;
    result = [U]myobject2;[/U]
    }
    
    return [B]result;[/B] // myobject or myobject2;
    }
    Last edited by Saletra; 08-23-2010 at 07:42 PM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,450
    Blog Entries
    7
    Rep Power
    20

    Default

    Like this?

    Java Code:
    Kasa result= wybierz();
    result.dodaj( ... );
    kind regards,

    Jos

  3. #3
    Saletra is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    I hope, this is it:)
    Thanks.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,450
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Saletra View Post
    I hope, this is it:)
    Thanks.
    Well, I think it is what you had in mind; give it a try.

    kind regards,

    Jos

Similar Threads

  1. returning an object from a method
    By bigj in forum New To Java
    Replies: 7
    Last Post: 01-08-2010, 12:39 PM
  2. Object and reference
    By katie in forum New To Java
    Replies: 2
    Last Post: 10-19-2009, 03:45 PM
  3. Very new to Java, how to reference an object
    By tornado in forum New To Java
    Replies: 3
    Last Post: 12-05-2008, 12:51 AM
  4. Object reference to number
    By dayneo in forum New To Java
    Replies: 4
    Last Post: 05-27-2008, 01:23 PM
  5. Getting the Object Reference Name
    By Deathmonger in forum New To Java
    Replies: 2
    Last Post: 03-12-2008, 02:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •