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. Which of the following could be

ID: 3745641 • Letter: U

Question

Use the following class for the next questions.

Which of the following could be used to instantiate a new Person p? Select all that apply. new Person p-("Carla Doe", "789 Broad Street, 26) Person p-new Person("Janet Jones, "456 Orange Avenue", 16.5); new Person(p): p-new Person0 Person p- new Person"John Smith, "123 Main Street", 42) Person p-new Person: Assume that another method has been defined that will return the a person's phone number. The method header is: public String getPhoneNumber() If p is an object of type Person, which of the following are correct statements to obtain p's phone number? Select all that apply. p getPhoneNumberd: getPhoneNumber(p); O p.toString: String-getPhoneNumber(p): String s p.getPhoneNumber0: O p.getPhoneNumber):

Explanation / Answer

Given Program-:

public class Person {

   private String name;

   private String address;

   private int age;

   public Person(String newName, String newAddress, int newAge) {

      name = newName;

      address = newAddress;

      age = newAge;

   }

   public String toString() {

      String s = name + " " + newAddress+ " " + age;

      return s;

   }

   public void vote() {

      System.out.println(name + " is voting.");

   }

}

Question 1 -: Which of the following could be used to instantiate a new Person p ?

Options-:  

a) new Person p = ("Carla Deo","789 Broad Street",26);

b) Person p = new Person ("janet Jones","456 Orange Avenue",16.5);

c) new Person(p);

d) p = new Person();

e) Person p = new Person ("john Smith","123 Main Street",42);

f) Person p = new Person ();

Answer is Option e) Person p = new Person ("john Smith","123 Main Street",42);

Explanation-: In program for parameter Person constructor data type String, String and int is required.

And syntax for that is Person p= new Person(“String parameter”,” String parameter”,int Paramter).

Question 2 -: Assume that another method has been defined that will return the a person's phone number.The method header is:

Options-:

a) p =getPhoneNumber();

b) getPhoneNumber(p);

c) p.toString();

d) String = getPhoneNumber();

e) String s = p.getPhoneNumber();

f) p.getPhoneNumber();

Answer is Option f) p.getPhoneNumber();

Explanation-: For calling any method we use object of the class dot(.) function name.

Question 3 -: What type of variable is age?

Options-:

a) Actual Parameter

b) Instance data

c) local variable

d) None of these

e) formal parameter

Answer is Option b) Instance data

Explanation-: Instance variables are declared in a class and but outside of the class. Whenever object of the class is created at that time instance variable get created (get memory space.)

Question 4 -: What type of variable is newName?

Options-:

a) formal parameter

b) actual parameter

c) local variable

d) instance data

e) none of these

Answer is Option a) formal parameter

Explanation-Formal parameter defined in method declaration. In above Program newname is defined in constructor. Actual parameter in which we pass actual value to the method.