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.

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.

LANGUAGE: JAVA

CHALLENGE:

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.

SOLUTION:

class FullName{
private String given;
    private String family;
    public FullName(String givenName, String familyName){
        given = givenName;
        family = familyName;
    }
    public String toString(){
        return family + “, ” + given;
    }
}

Add comment