Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Name -
- //Date -
- //Class -
- //Lab -
- import static java.lang.System.*;
- public class AddStrings
- {
- //instance variables
- private String first, last;
- private String sum;
- //default constructor (No parameteters)
- // initialize instance variables to
- // default values
- public AddStrings()
- {
- first = "";
- last = "";
- }
- //overloaded constructor
- // initialize the instance variables
- // to the passed parameters
- // by calling the set method
- public AddStrings(String one, String two)
- {
- //to call a method in a class
- //from inside the class, write
- //method name(parameters)
- setStrings(one,two);
- }
- public void setStrings(String one, String two)
- {
- //initialize instance variables
- first = one;
- last = two;
- }
- public void add( )
- {
- sum = first + " " + last;
- }
- //redfine toString for obejects of
- // the class
- public String toString()
- {
- String output="";
- output += "first :: " + first + "\n" + "last :: " + last + "\n" + "sum :: " + sum;
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement