Ask Question
17 October, 13:49

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. 17 October, 16:25
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers