Results 1 to 5 of 5
  1. #1
    captain alge is offline Member
    Join Date
    Mar 2011
    Posts
    25
    Rep Power
    0

    Default methods and returns

    Greetings,
    I'm a little bit confused about method returns, I know how to set a method to return a value, but how is that value then accessed by the class/method that called it?
    cheers

  2. #2
    akiravelmont is offline Member
    Join Date
    Mar 2011
    Location
    bangalore
    Posts
    61
    Rep Power
    0

    Post method return

    let consider a program


    class Second{
    String newMethod(){
    return "this is how the value returned";
    }
    }
    class First{
    public static void main(String a[]){
    Second e=new Second();
    System.out.println("returned value - "+e.newMethod());
    }
    }

    after creating the object for Second class the jvm go to execute print statement.
    it prints the first string and then immediately we call the method newMethod() so it go to that method, inside that method we returned some value that value is stored in object e. the value in object e displayed on console.

    Hope you understand.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

  4. #4
    captain alge is offline Member
    Join Date
    Mar 2011
    Posts
    25
    Rep Power
    0

    Default

    cheers akiravelmont, that helped a lot

    @Darryl.Burke, that didn't, I had already read that tutorial

  5. #5
    akiravelmont is offline Member
    Join Date
    Mar 2011
    Location
    bangalore
    Posts
    61
    Rep Power
    0

    Thumbs up

    most welcome. if you have any queries message me. i will help you:):)

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Average returns 0
    By jehduncs in forum New To Java
    Replies: 2
    Last Post: 12-03-2010, 06:29 PM
  3. .DAY_OF_WEEK always returns 7
    By shurgs in forum New To Java
    Replies: 2
    Last Post: 08-20-2010, 02:32 PM
  4. IndexSearch.docfreq returns 0.0
    By noir in forum Lucene
    Replies: 0
    Last Post: 04-26-2010, 09:32 AM
  5. What's the need for co-variant returns ?
    By ajeeb in forum New To Java
    Replies: 0
    Last Post: 03-23-2009, 09:56 AM

Posting Permissions

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