36.4k views
4 votes
For questions 1 – 3, use the following partial class definitions:

public class A1
{
public int x;
private int y;
public int z; …
}
public class A2 extends A1
{
public int a; private int b; …
}
public class A3 extends A2
{
private int q; …
}

1) Which of the following is true with respect to A1, A2, and A3?
a) A1 is a subclass of A2 and A2 is a subclass of A3
b) A3 is a subclass of A2 and A2 is a subclass of A1
c) A1 and A2 are both subclasses of A3
d) A2 and A3 are both subclasses of A1
e) A1, A2 and A3 are all subclasses of the class A

2) Which of the following lists of instance data are accessible in class A2?
a) x,y,z,a,b
b) x,y,z,a
c) x,z,a,b
d) z,a,b
e) a,b

3) Which of the following lists of instance data are accessible in A3?
a) x,y,z,a,b,q
b) a,b,q
c) a,q
d) x,z,a,q
e) x,a,q

User Davivid
by
6.4k points

1 Answer

6 votes

Answer:

QUESSTION 1: B

QUESTION 2: C

QUESTION 3: D

Step-by-step explanation:

In question 1, since A3 extends A2, it implies A3 is the subclass of A2 and A2 is its super class, same applies to the relationship between A1 and A2, the extends keyword is used to indicate inheritance in the child class (subclass)

In question 2, the class A2 has two declared instance variables (a,b) It has also inherited the public variables of its superclass (A1) so it has the x,z (Inherited variables) and a,b (its own variable)

The same explanation in question 2 applies to question three. The Class A3 has access to all the public fields of A1 and A2 as well as its own declared field x,z,a (Inherited public fields) q Its own field.

User Matlabbit
by
6.2k points