Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following code: public class Person { private int age; private String status; public Person ( ) { this.status = young; } this. age

Given the following code:
public class Person {
private int age;
private String status;
public Person(){
this.status = "young";
}
this. age =0;
public void getolderByYears(int years){
this.age = this.age + years;
if (this.age >1){
status = "old";
}
}
}
public class Main {
public static void main(String[] args){
Person bubbles = new Person();
Person buttercup = new Person();
Person blossom = new Person();
ArrayList Person > people = new ArrayList >();
people. add (bubbles);
people. add (buttercup) ;
people. add (blossom);
int ageAmount =1;
for (Person p : people){
p. getolderByYears (ageAmount);
ageAmount = ageAmount +1 ;
}
//POINT A
//POINT B
}
}
Part 1
We hit POINT A once for each of the people (bubbles, buttercup and blossom) in the list -- each time
referenced by "p". Which of those people (on their "turn" through the loop) will have the status set to
"old"?
(a) bubbles
(b) buttercup
(c) blossom
Select all possible options that apply.
Part 2
At Point B, what is the value of ageAmount?
(a)3
(b)2
(c)4
(d)1
(e)0
(f)5
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

7. each +1)

Answered: 1 week ago