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

Consider the following pseudocode class definitions public class A private int x

ID: 3571239 • Letter: C

Question

Consider the following pseudocode class definitions public class A private int x public int y//constructors and other methods not shown end A public class B extends A private int z//constructors and other methods not shown end B Consider the following declaration that appears in a class other than A or B. B leftarrow new B () Which of the following statements is (are) valid? b middot x leftarrow 1 b middot y leftarrow 2 b middot z leftarrow 3 None II only III only II n and III only I, II, . and III

Explanation / Answer

Answer:Option 'D' is the correct.

Explanation:

In this code we have two classes 'A' and 'B' .The class 'B' is inherited from class 'A'.In class 'A' we have two varibles one 'x' declared as private variable and another one is 'y' declared as public.In class 'B' we have one variable 'z' declared as private.

The declartion B b=new B() is created an object of class B.Here the option D is correct answer because private member variable x is only access by class A.Because the one class variable cannot acces the other class variable if it is declared as private. So b is an object of class B it can access both variables yand z but it does'nt access the variable x.Because the object b can access the variable y because of it is declared as public.So public can access by any one so 'b.y' is valid.Then as usual 'b.z' is also valid because private is accessable by same class object.

Here the main point is private variables cannot accessable other class members.The private variable can only accessable by same class object.