5-11 ReturnString

posted Apr 3, 2014, 9:14 AM by Dlovan ismail   [ updated Apr 3, 2014, 9:15 AM ]
/*
This program demonstrates a method that
returns a reference to a String object.
*/

package returnstring;

public class ReturnString 
{
        public static void main(String[] args) 
        {
            String customerName;

            customerName = fullName("John","Martin");
            System.out.println(customerName);
        }

        /*
        The fullName method accepts two String arguments
        containing a first and last name. It concatenates
        them into a single String object.
        @param first The first name,
        @param iast The last name.
        @return A reference to a String object containing
                  the first and last names.
        */

        public static String fullName(String first , String last)
        {
            String name;

            name = first + " " + last;
            return name;
        }
    
}

ċ
ReturnString.java
(1k)
Dlovan ismail,
Apr 3, 2014, 9:14 AM
Comments