Question
9. Consider the following code: public class A1 { public int x; private int y; ... } public class A2 extends A1 { public int
9.
Consider the following code: public class A1 { public int x; private int y; ... } public class A2 extends A1 { public int a; private int b; ... } public class A3 extends A2 { private int q; ... } Which of the following sets of instance variables are directly accessible in class A3? (2 points)
a, b, q | |
a, q | |
x, a, b, q | |
x, a, q | |
x, y, a, b, q |
10.
Consider the following code: public class A1 { public int x; private int y; ... } public class A2 extends A1 { public int a; private int b; ... } public class A3 extends A2 { private int q; ... } Which of the following is true regarding the use of instance variable y in class A1? (2 points)
It is directly accessible only in A1 | |
It is directly accessible only in A3 | |
It is directly accessible in A1 and A2 | |
It is directly accessible in A1, A2, and A3 | |
It is not directly accessible in any of the three classes |
11.
Consider the following code: public class B1 { private int i; private int j; ... } public class B2 extends B1 { private int m; private int n; ... } public class B3 extends B2 { private int z; ... } Which of the following sets of instance variables are directly accessible in class B2? (2 points)
i, j, m, n | |
i, j, m, n, z | |
m, n | |
m, n, z | |
z |
12.
Consider the following code: public class B1 { private int i; private int j; ... } public class B2 extends B1 { private int m; private int n; ... } public class B3 extends B2 { private int z; ... } Which of the following sets of instance variables are directly accessible in class B3? (2 points)
i, j, m, n | |
i, j, m, n, z | |
i, j, z | |
m, n, z | |
z |
13.
All classes in Java are directly or indirectly subclasses of the _______ class. (2 points)
Object | |
Reference | |
String | |
this | |
Wrapper |
14.
Assume the Student and Employee classes each extend the Person class. The Student class overrides the getMoney method in the Person class. Consider the following code: Person p1, p2, p3; int m1, m2, m3; p1 = new Person(); m1 = p1.getMoney(); // assignment 1 p2 = new Student(); m2 = p2.getMoney(); // assignment 2 p3 = new Employee(); m3 = p3.getMoney(); // assignment 3 The reference to getMoney in assignment 1 is to the class (2 points)
Child | |
Person | |
Student | |
Employee | |
this cannot be determined by examining the code |
15.
Assume the Student and Employee classes each extend the Person class. The Student class overrides the getMoney method in the Person class. Consider the following code: Person p1, p2, p3; int m1, m2, m3; p1 = new Person(); m1 = p1.getMoney(); // assignment 1 p2 = new Student(); m2 = p2.getMoney(); // assignment 2 p3 = new Employee(); m3 = p3.getMoney(); // assignment 3 The reference to getMoney in assignment 3 is to the ________ class. (2 points)
Child | |
Employee | |
Person | |
Student | |
this cannot be determined by examining the code |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started