Question: Given the following code ( which is the same as in Q 1 ) : public class Person { private int age; public Person (

Given the following code (which is the same as in Q1):
public class Person {
private int age;
public Person(){
age =1;
}
public int getAge(){
return age;
}
public void getOlderByYears(int years){
age = age + years;
years = years +1;
// POINT A
}
}
public class Main {
public static void main(String[] args){
Person jean = new Person();
int ageAmount =3;
//POINT B
jean.getOlderByYears(ageAmount);
//POINT C
}
}
Part 1
When we run the Java program above, what is the value of years at Point A?
(a)
expression does not compile at Point A
(b)
3
(c)
4
(d)
0
(e)
2
(f)
1
0%
Part 2
When we run the Java program above, what is the value of years at Point B?
(a)
3
(b)
1
(c)
2
(d)
4
(e)
expression does not compile at Point B
(f)
0
0%
Part 3
When we run the Java program above, what is the value of years at Point C?
(a)
expression does not compile at Point C
(b)
0
(c)
3
(d)
1
(e)
4
(f)
2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!