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 C?
(a) expression does not compile at Point C
(b)0
(c)2
(d)4

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!