46.4k views
2 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 B2? (2 points)

1) i, j, m, n, z
2) i, j, m, n
3) i, m, n
4) m, n
5) z

User Jon Abrams
by
8.5k points

1 Answer

1 vote

Answer:

4. m, n

Step-by-step explanation:

Public variables are those variables that are accessible to every class or function in the program.

Private variables are variables that are accessible to only specific classes or functions in the code.

The integers i, j, m, n, z are private variables that can only be accessible to the classes in which they were declared.

For class B2, the private variables declared in it are the integers i and j. Those are the only variables that can be directly accessed by it.

User Danwyand
by
8.8k points