Ask Question

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.

+3
Answers (1)
  1. 14 July, 14:49
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers