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

Given a class called Person , as specified below. Also imagine there is a Person

ID: 3726121 • Letter: G

Question

Given a class called Person , as specified below. Also imagine there is a Person object called person1 ,created in a client class. Which of the statement will print the values of instance variables, name and age, of person1 in the client class? Code for class Person is as follows:

public class Person {

private String name;

private int age ;

public int getAge() { return age; }

public int getName(){return name; }

public void setName(String name) { this.name - name; }

pubic void setAge(int age) { this.age = age;}

}

System.out.println( " Name is: " + name+ "age is: " + age );

person1.setAge(24);

person1.setName("ABC");

System.out.println( " Name is: " + name+ "age is: " + age );

person1.getAge();

person1.getName();

System.out.println( " Name is: " + name+ "age is: " + age );

System.out.println( " Name is: " + person1.getName()+ "age is: " + person1.getAge() );

A)

System.out.println( " Name is: " + name+ "age is: " + age );

B)

person1.setAge(24);

person1.setName("ABC");

System.out.println( " Name is: " + name+ "age is: " + age );

C)

person1.getAge();

person1.getName();

System.out.println( " Name is: " + name+ "age is: " + age );

D)

System.out.println( " Name is: " + person1.getName()+ "age is: " + person1.getAge() );

Explanation / Answer

Dear Student,

Option D is correct.

remaining option will produce an error.

===============================================================

KIndly Check and Veriufy THanks..!!!

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