19.9k views
14 votes
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?

i, j, m, n

i, j, m, n, z

i, j, z

m, n, z

z

2 Answers

8 votes

Answer:

4. m, n, z

Step-by-step explanation:

This is because B3 extends off of B2. Meaning it has its own instance variables accessible, and can directly access the variable from it's super class, which is B2, which has m, and n.

User Arslan Tariq
by
4.9k points
4 votes

Answer:

The answer is "z"

Step-by-step explanation:

In this question, the "z" instance variable is correct because inside the class "B3" it declared a private variable "z", which is applied in the methods or data members or variables, and it is only accessible within the class, that they have been declared, and when we create its instance so, the object has been instantiated, and it is generated and accessible to all the builders, methods, or class blocks.

User Piyushj
by
4.5k points