In: Computer Science
The answer to this question is as follows:
The code is as follows:
class Patient
{
//decalring the variables patientId,lastName;
private int patientId;
private String lastName;
//Decalring the constructor
Patient( int patientId,String lastName)
{
this.patientId=patientId;
this.lastName=lastName;
}
//Decalring the getPatientId
int getPatientId()
{
return this.patientId;
}
//Declaring the getLastName
String getLastName()
{
return this.lastName;
}
//Declaring the setpatientID
void setPatientId(int patientId)
{
this.patientId=patientId;
}
//Declarint the setLastName
void setLastName(String lastName)
{
this.lastName=lastName;
}
}
public class MyClass {
public static void main(String args[]) {
int patientId=1;
String lastName="Jackson";
Patient p=new Patient(patientId,lastName);
System.out.println("Get method PatientId:
"+p.getPatientId());
System.out.println("Get method Patient Lastname:
"+p.getLastName());
p.setPatientId(patientId);
p.setLastName(lastName);
}
}
The input and output with screenshot