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..!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.