Ask Question
20 September, 17:58

Write a class named FullName containing: Two instance variables named given and family of type String. A constructor that accepts two String parameters. The value of the first is used to initialize the value of given and the value of the second is used to initialize family. A method named toString that accepts no parameters. toString returns a String consisting of the value of family, followed by a comma and a space followed by the value of given.

+4
Answers (1)
  1. 20 September, 19:29
    0
    public class FullName {

    private String givenName;

    private String familyName;

    //The constructor

    public FullName (String givenName, String familyName) {

    this. givenName = givenName;

    this. familyName = familyName;

    }

    //Method toString

    public String toString () {

    String fullName = familyName+", "+givenName;

    return fullName;

    }

    }

    Explanation:

    As required by the question. A class is created with two fields

    private String givenName;

    private String familyName;

    The constructor initializes the values for this fields

    The method toString concatenates the familyName and givenName and returns the fullName
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a class named FullName containing: Two instance variables named given and family of type String. A constructor that accepts two ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers