returns values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dylan Hall
    New Member
    • Nov 2011
    • 1

    returns values

    when i write the following program---


    public class Public_Private
    {
    public static void main(String args[])
    {
    Personal Dylan = new Personal();
    Dylan.Name(Dyla n.name);
    Dylan.Birthdate (Dylan.birthdat e);
    Dylan.Weight(Dy lan.weight);
    Dylan.Hobbies(D ylan.hobbies);
    Dylan.Religion( Dylan.religion) ;
    Dylan.Address(D ylan.address);
    Dylan.Visit(Dyl an.visit);

    }


    }
    class Personal
    {
    String name = "Name";
    String birthdate = "may 25, 1995";
    String weight = "3.5 lbs";
    String hobbies = "Sitting, Music, Computers";
    String religion = "Freestyle Christian";
    String address = "3970 wouldnent you like to know :P";
    String visit = "Julliard School Of Fine Arts";
    public static String Name(String MyName)
    {
    System.out.prin tln(MyName);
    String name = "Name Method Finished";
    return name;
    }
    public static String Birthdate(Strin g MyBirthdate)
    {
    System.out.prin tln(MyBirthdate );
    String birthdate = "Birthdate method finished";
    return birthdate;
    }
    public static String Weight(String MyWeight)
    {
    System.out.prin tln(MyWeight);
    String weight = "Weight method finished";
    return weight;
    }
    public static String Hobbies(String MyHobbies)
    {
    System.out.prin tln(MyHobbies);
    String hobbies = "Hobbies method finished";
    return hobbies;
    }
    public static String Religion(String MyReligion)
    {
    System.out.prin tln(MyReligion) ;
    String religion = "Religion method finished";
    return religion;
    }
    public static String Address(String MyAddress)
    {
    System.out.prin tln(MyAddress);
    String address = "Address method finished";
    return address;
    }
    public static String Visit(String MyVisit)
    {
    System.out.prin tln(MyVisit);
    String visit = "visit method finished";
    return visit;
    }




    }

    ---
    Instead of it printing "Name" and then returning the string "name method finished" it just prints "name" and skips the return altogether moving onto the next method call. why cant i get it to return the Strings?
  • Maraj
    New Member
    • Nov 2011
    • 24

    #2
    You should do like this and methods will be called one after other because you have written them in sequence.
    Code:
    String name=Dylan.Name(Dylan.name);
    Now what Name() will return will be stored in name.
    Now do same like this for remaining methods.

    Comment

    Working...