Hi, I am new to learning Java as I have this in my current semester and I had quiz and I got 2 questons wrong out of 10 but it didn't show the right answer. I am curious to know what is the correct answer.
The question number 1 is:
The following method is defined in the Person.java class
public void setAddress(String _address) {
this.address = _address;
}
In the testDriver.java class, the following code is in the main method
public static void main(String[] args) {
// create test case 1 - a person owning a pet dog
Person p1 = new Person( "25 somewhere Street","Kathleen","2000");
Animal myPet = new Animal("CockerSpaniel","Fido");
p1.addAPet(myPet);
// your answer code will be added here
System.out.println("I have a person object : " + p1.toString());
}
What is the exact line of code to add if we wish to change the address field in the person object p1 to be "12 ross drive"
My answer was:
setAddress add1 = new setAddress ("12 ross drive");
--------------------------------------------------------------------------
Question 2:
The following code excerpt is taken from a Person.java file,
/**
* u/param _pet the pet animal to associate
* the calling method will provide an Animal object as an argument when this
*method is called. This method will save that Animal object onto the current
*Person object into the class attribute named pet.
*/
public void addAPet(Animal _pet) {
this.pet =
}
Complete the line of code: this.pet =
My answer was :
new Animal(_pet);
Cheers. Happy coding!