Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
3 replies Latest Post - ‏2011-11-16T02:43:12Z by dev1008
SumitTrehan
SumitTrehan
2 Posts
ACCEPTED ANSWER

Pinned topic How does an Object is returned in Java vs C?

‏2011-09-07T04:36:31Z |
Hello experts,

I have a doubt that how does an object is returned by a method in Java.

Inferences for above statement:
In C we know that the memory allocated locally inside a function will vanish when the function returns



char *getName() 
{ 

char name[]=
"Sumit"; 

return name 
}


The caller of the function will get a pointer to the array.Although the pointer points a garbage unknown location since the array was local, it has now been destroyed.

Now I have a doubt the same thing works in Java

{code}
public String getName()
{
String name="Sumit"; //name here is local as above;memory allocated for the object locally
return name;
}

The caller of the method will correctly get the desired String passed.

Now my question is How the pointer (or reference in Java) is returned when it is compared to C.
Hope I made my points clear

Hoping to get a reply soon
Regards
Updated on 2011-11-16T02:43:12Z at 2011-11-16T02:43:12Z by dev1008
  • todd12
    todd12
    1 Post
    ACCEPTED ANSWER

    Re: How does an Object is returned in Java vs C?

    ‏2011-11-08T06:38:05Z  in response to SumitTrehan
    can we use the concept of applets here for using the graphical terms to make it more attractive or not,according to me the object is called through a class or method in java and also returned through calling the objects with the class

    ______________________
    http://www.canamlimo.com/toronto-airport-limo.html
    • dev1008
      dev1008
      2 Posts
      ACCEPTED ANSWER

      Re: How does an Object is returned in Java vs C?

      ‏2011-11-16T02:43:12Z  in response to todd12
      Dear Friends....

      How you are post your query because i would like post my new Question in this forum. Can you please help me on this. From where we can post new topic. Your early response is always appreciated.
      Thnx
      Rahul
  • seohulu
    seohulu
    8 Posts
    ACCEPTED ANSWER

    Re: How does an Object is returned in Java vs C?

    ‏2011-11-14T20:05:50Z  in response to SumitTrehan
    there aren't pointers from the java programmer's perspective, only references, in your example, there are no way for caller to grab the address of "submit", the caller has to have his own reference to receive the "submit" value ,like this "String callersRef = getName();"

    Acoolme is an Online Marketing Software Platform And Social Community