Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Inheritance and Accessibility Modifiers (6 points) Consider the following partia

ID: 3715288 • Letter: I

Question

Inheritance and Accessibility Modifiers (6 points) Consider 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; ... }

a. Which instance data (class variables) are accessible in class A2? List all accessible ones in A2.

b. Which instance data (class variables) are accessible in class A3? List all accessible ones in A3.

c. Which classes get access to the y variable defined in A1?

Explanation / Answer

Private Access Modifier can be used with in the class
Protected Access Modifier can be used in with in the package
Public Access Modifier can be used any where

A. Only public int x; protected int z; from A1 class can be inherited because other variables declared with private modifiers
List:
Public int x;
Protected int z;
Protected int a;
Private int b;


B. Only public int x; Protected int z; from A1 class can be inherited to A2 and from A2 only Protected int a; can be inherited to A3.
List :
Private int q;
Public int x;
Protected int z;
Protected int a;

C.No,class can't be access the variable y because it declares private modifier