Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the following class for the next questions. What type of variable is s? inst

ID: 3745656 • Letter: U

Question

Use the following class for the next questions.

What type of variable is s? instance data o local varlable e none of these is correct actual parameter formal parameter Which statements would print a text representation of a Person object p to the console? Select all that apply p.toString: O System.out.printiString.toip): a System.out.printip.toStrine) System.out.printíp): Another method that might be added is one to access a person's age. The method header public int getAgeC) What statement should be placed inside this method? Another method that might be added is one to modify a person's name. The next three questions ask about this method. According to convention, what would be the best name for such a method? e getName o changeName updateName setName By convention, what would be the return type of the method? o void none of these is correct String Person

Explanation / Answer

1. What type of variable is s?

Answer:

s is an local variable because it's declared inside a method.

It's scope is only limited to the method toString().

2.Which statements would print a text representation of a Person object p to the console?

Select all that apply?

Answer:

p.toString() only returns the method, but it doesn't print anything.

System.out.print(String.to(p)) is a invalid method because there's no method with the name to.

System.out.print(p.toString()) prints the text representation of a person object p to the console.

System.out.print(p) also prints the text representation of a person object p to the console.

3.Another method that might be added to one to access a person's age. The method header is

public int getAge()

What statement should be placed inside this method?

Answer:

public int getAge()

{

return age;

}

4.Another method that might be added is one to modify a person's name. The next three questions ask about this method.

According to convention, what would be the best name for such a method?

Answer:

updateName is the best name for this method because it let's the programmer know what the method is without any confusion.

5.By convention, what would be the return type of the method?

Answer:

The return type would be void because the method only modifies the name.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote