Ask Question
8 February, 14:38

Public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ... } Which of the following lists of instance data are accessible in class A2?

1. a, b

2. x, y, z, a, b

3. x, z, a, b

4. x, y, z, a

5. z, a, b

+1
Answers (1)
  1. 8 February, 15:05
    0
    The correct option is option 3.

    Step-by-step explanation:

    The public variable is accessible to all the classes

    A private variable is accessible to only the class in which it is defined

    A protected variable is accessible in the defining and derived classes

    Now as the class A2 is under consideration, so the two variables which are defined in A2 are both accessible by A2 which are the protected int a and the private int b.

    Now for the other variables, public int x is accessible to all the classes as it is a public variable.

    Private int y is defined in class A1 so it is not accessible to class A2.

    Protected int z is defined in class A1 but A2 is derived from A1 thus this is also accessible by A2.

    Private int q is defined in class A3 so it is not accessible to class A2.

    Thus a, b, x and z are the four variables accessible by the class A2 sso option 3 is the correct option.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } ...” in 📗 Mathematics if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers