96.4k views
2 votes
Create a class named Person that holds two String objects for the person’s first and last name (firstName and lastName). Include a blank constructor that takes no parameters and an overloaded constructor that requires an argument for each field. Add the firstName and lastName data fields to the Person class. Include a blank constructor that takes no parameters and an overloaded constructor that requires an argument for each field. Include a blank constructor and an overloaded constructor. Include get methods for each field. Add get methods for each data field in the Person class.

1 Answer

4 votes

Final answer:

The question involves creating a 'Person' class in a programming language with two constructors and getter methods for the 'firstName' and 'lastName' fields.

Step-by-step explanation:

The student is asking how to create a class in an object-oriented programming language such as Java. The class should be called Person and contain two private data fields for the person's first and last names. The following code snippet demonstrates such a class with a blank constructor and an overloaded constructor, as well as getter methods:

public class Person {
private String firstName;
private String lastName;

// Blank constructor
public Person() {
this.firstName = "";
this.lastName = "";
}

// Overloaded constructor
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

// Get methods
public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}
}
User Natia
by
7.8k points