The following two class definitions are used in this question: public class Abel
ID: 3584937 • Letter: T
Question
The following two class definitions are used in this question: public class Abel {
private int x;
public Abel(int x) {
this.x = x;
}
public int getX() {
return x;
}
public void f() {
System.out.println("f in Abel x is " + x);
}
public void g() {
System.out.println("g in Abel x is " + x);
}
}
public class Baker extends Abel {
private int y;
public Baker(int x, int y) {
super(x);
this.y = y;
}
public int getY() {
return y;
}
public void f() {
System.out.println("f in Baker x is " + getX() + " y is " + y);
}
public void h() {
System.out.println("h in Baker x is " + getX() + " y is " + y);
}
}
A program begins with the following statements that create three objects:
Abel arthur = new Abel(23);
Baker barbara = new Baker(29, 31);
Abel carl = new Baker(37, 41);
Then the program continues with the following nine statements. Out of these, two will cause compiler errors. Mark those by writing *compiler error* next to each of them. For the other seven statements, write next to them what will be displayed when that method call is executed. Keep them in the same order (1-9)
1. arthur.f();
2. arthur.g();
3. arthur.h();
4. barbara.f();
5. barbara.g();
6. barbara.h();
7. carl.f();
8. carl.g();
9. carl.h();
Explanation / Answer
1. arthur.f(); - f in Abel x is 23
2. arthur.g(); - g in Abel x is 23
3. arthur.h(); - compilation error
4. barbara.f(); - f in Baker x is 29 y is 31
5. barbara.g(); - g in Abel x is 29
6. barbara.h(); - h in Baker x is 29 y is 31
7. carl.f(); - f in Baker x is 37 y is 41
8. carl.g(); - compilation error
9. carl.h();-h in Baker x is 37 y is 41
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.