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.

Respuesta :

ijeggs

Answer:

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