Ask Question
25 June, 23:33

Which of the following is true regarding the use of instance variable j in class B1?

A) It is directly accessible only in B1

B) It is directly accessible only in B2

C) It is directly accessible only in B3

D) It is directly accessible in B1 and B2

E) It is directly accessible in B1, B2, and B3

+4
Answers (1)
  1. 26 June, 03:13
    0
    Answer: A) It is directly accessible only in B1

    Explanation: In the given chunk of code, Class B1 is a base class. Class B2 is derived class of class B1. Class B3 is derived class of B2. As you can see class B1 has two members or instance variables i and j. Instance variable cannot be directly accessible by both B2 and B3. If you see this statement of the given code private int j; the keyword private is used with the variable j. This keyword is called access specifier. Access specifiers specifies how the members of a class can be accessed. These members are attributes and methods of that class. Any member of a class that are declared private cannot be inherited by derived classes of that class. Additionally these private members cannot be accessed from within any method inside derived class. So j is directly accessible only in B1. You can access a private instance variable from within the same class or can access it through the methods of class.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Which of the following is true regarding the use of instance variable j in class B1? A) It is directly accessible only in B1 B) It is ...” 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