daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Sep 19th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. //Name -
  3. //Date -
  4. //Class -
  5. //Lab  -
  6.  
  7. import static java.lang.System.*;
  8.  
  9. public class AddStrings
  10. {
  11.    //instance variables
  12.    private String first, last;
  13.    private String sum;
  14.  
  15.    //default constructor (No parameteters)
  16.    // initialize instance variables to
  17.    //    default values
  18.    public AddStrings()
  19.    {
  20.        first = "";
  21.        last = "";
  22.    }
  23.  
  24.    //overloaded constructor
  25.    //   initialize the instance variables
  26.    //   to the passed parameters
  27.    //   by calling the set method
  28.    public AddStrings(String one, String two)
  29.    {
  30.        //to call a method in a class
  31.        //from inside the class, write
  32.        //method name(parameters)
  33.        setStrings(one,two);
  34.    }
  35.  
  36.    public void setStrings(String one, String two)
  37.    {
  38.        //initialize instance variables
  39.        first = one;
  40.        last = two;
  41.    }
  42.  
  43.     public void add( )
  44.     {
  45.         sum = first + " " + last;
  46.     }
  47.     //redfine toString for obejects of
  48.     // the class
  49.     public String toString()
  50.     {
  51.         String output="";
  52.         output += "first :: " + first + "\n" + "last :: " + last + "\n" + "sum :: " + sum;
  53.         return output;
  54.     }
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top