14.8k views
15 votes
Define a class named person that contains two instance variables of type string that stores the first name and last name of a person and appropriate accessor and mutator methods. Also create a method named displayDetails that outputs the details of a person

1 Answer

3 votes

Answer:

Answered below

Step-by-step explanation:

//Program is written using Java programming language.

Class Person {

private string firstName;

private string lastName;

void set firstName(string a){

firstName = a;

}

string getFirstName(){

return firstName;

}

void setLastname( string b){

lastName = b;

}

string getLastName( ){

return lastName;

}

void displayDetails( ) {

System.out.print(firstName);

System.out.print (lastName);

}

}

//Test program

Class Main{

public static void main(String args [] ){

Person person = new Person( )

person.setFirstName("Karen")

System.out.print(person.getFirstName)

person.displayDetails()

}

}

User Neo Post Modern
by
5.8k points