Ask Question
9 May, 03:52

For the questions below, use the following partial class definitions : 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

+3
Answers (1)
  1. 9 May, 04:31
    0
    Option 3 i. e., x, z, a, b is correct.

    Explanation:

    In the above program which is in the Java Programming Language, there is the class with public access modifier and inside the class, we declare three integer data type variable with different access modifier, first variable 'x' with public modifier then, second variable 'y' with private modifier and third variable with protected modifier.

    Then, they inherit the 'A1' class in the new class 'A2' inside which we declare two integer data type variable, the first variable is 'a' with protected modifier and second variable 'b' with private modifier.

    So, you can clearly see that we cannot access the private variable of the parent class but you can access the public variable outside the class as well as protected also but in some conditions, and in other extended class we can access both public, private and protected variable through the class 'A2'. That's why we cannot access the private member of the parent class.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “For the questions below, use the following partial class definitions : public class A1 { public int x; private int y; protected int z; ... ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers