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

This is way over my head. Please help. 3.5 Consider classes C1, C2, and C3. Answ

ID: 667251 • Letter: T

Question

This is way over my head. Please help.

3.5 Consider classes C1, C2, and C3. Answer the following questions. class c1 class C2 extends C1 class C3 extends C2 1 public int x1; protected int x2; private int x3; public void c1Method1) t protected void c1Method2) rtected void c2Method2 private void c1Method30 Co public int y1; protected int y2; private int y3; public void c2Method1) ) public int zi; protected int z2; private int z3; public void c3Method1) C protected void c3Mthod2 private void c3Method30 Co private void c2Method3) o e void c2Method3()

Explanation / Answer

Answers

3.5

1.

The instance variables x1, x2 and x3 declared in the class C1 are accessible to the same class method public c1Method1.

Class C1

public

protected

private

C1Method1()

Yes

Yes

Yes

2.

The instance variables x1, x2 and x3 declared in the class C1 are accessible to the same class protected method c1Method2.

Class C1

public

protected

private

C1Method2()

Yes

Yes

Yes

3.

The instance variables x1, x2 and x3 declared in the class C1 are accessible to the same class method private c1Method3.

Class C1

public

protected

private

C1Method3()

Yes

Yes

Yes

-------------------------------------------------------------------------------------------------------------------

4.

Accessibility of modifiers in subclass

C2 class extends the class C1

Modifier

Class ,C1

Class, C2

public

Yes

Yes

protected

Yes

Yes

private

Yes

No

From as per above rule,

The variables x1 (public) and, x2 (protected) are accessible to Class, C2 method

c2Method1

5.

Accessibility of modifiers in subclass

C2 class extends the class C1

Modifier

Class ,C1

Class, C2

public

Yes

Yes

protected

Yes

Yes

private

Yes

No

From as per above rule,

The variables x1 (public) and, x2 (protected) are accessible to Class, C2 method

c2Method2

6.

Accessibility of modifiers in subclass

C2 class extends the class C1

Modifier

Class ,C1

Class, C2

public

Yes

Yes

protected

Yes

Yes

private

Yes

No

From as per above rule,

The variables x1 (public) and, x2 (protected) are accessible to Class, C2 method

c2Method3

-------------------------------------------------------------------------------------------------------------------

7.

Accessibility of modifiers in subclass

C3 class extends the class C2 that in turn extends C1

Modifier

Class ,C1

Class, C2

Class, C3

public

Yes

Yes

Yes

protected

Yes

Yes

Yes

private

Yes

No

No

From as per above rule,

The variables x1 (public) and, x2 (protected) are accessible to Class, C3 method

c3Method1

8.

Accessibility of modifiers in subclass

C2 class extends the class C1

Modifier

Class ,C1

Class, C2

Class, C3

public

Yes

Yes

Yes

protected

Yes

Yes

Yes

private

Yes

No

No

From as per above rule,

The variables x1 (public) and, x2 (protected) are accessible to Class, C3 method

c3Method2

9.

Accessibility of modifiers in subclass

C3 class extends the class C2 that in turn extends C1

Modifier

Class ,C1

Class, C2

Class, C3

public

Yes

Yes

Yes

protected

Yes

Yes

Yes

private

Yes

No

No

From as per above rule,

From as per above rule,

The variables x1 (public) and, x2 (protected) are accessible to Class, C3 method

c3Method3

-------------------------------------------------------------------------------------------------------------------

10.

Since y1, y2 and y3 are declared in class C2, c1Method1 is declared in class C1 , it is not possible to access any variable from the method c1Method1.

Descendent class C2 from C1 can access the variables of class C1.

Preceded class C1 cannot access the descendent class instant variables.

11.

Since y1, y2 and y3 are declared in class C2, c1Method2 is declared in class C1, it is not possible to access any variable from the method c1Method1.

Descendent class C2 from C1 can access the variables of class C1.

Preceded class C1 cannot access the descendent class instant variables.

.

12.

Since y1, y2 and y3 are declared in class C2, c1Method3 is declared in class C1, it is not possible to access any variable from the method c1Method1.

Descendent class C2 from C1 can access the variables of class C1.

Preceded class C1 cannot access the descendent class instant variables.

-------------------------------------------------------------------------------------------------------------------

13.

Since z1, z2 and z3 are declared in class C3, c1Method1 is declared in class C1,

it is not possible to access any variable from the method c1Method1.

Descendent class C3 from C2 can access the instant variables of class C2 as per modifier of the instance variable.

Base class C1 cannot access the child class C3 instant variables.

14.

Since z1, z2 and z3 are declared in class C3, c1Method1 is declared in class C1,

it is not possible to access any variable from the method c1Method2.

Descendent class C3 from C2 can access the instant variables of class C2 as per modifier of the instance variable.

Base class C1 cannot access the child class C3 instant variables.

.

15.

Since z1, z2 and z3 are declared in class C3, c1Method1 is declared in class C1,

it is not possible to access any variable from the method c1Method2.

Descendent class C3 from C2 can access the instant variables of class C2 as per modifier of the instance variable.

Base class C1 cannot access the child class C3 instant variables.

--------------------------------------------------------------------------------------------------------------------------------------------

16.

From c2Method1 of class C2, it possible to call the methods of its base class C1 methods public and protected methods c1Method1 and c1Method2. It is not possible to call the private method c1Method3 of class C1.

17.

From c2Method2 of class C2, it possible to call the methods of its base class C1 methods public and protected methods c1Method1 and c1Method2. It is not possible to call the private method c1Method3 from c2Method2 of class C2.

18.

From c2Method3 of class C2, it possible to call the methods of its base class C1 methods public and protected methods c1Method1 and c1Method2. It is not possible to call the private method c1Method3 from c2Method3 of class C2.

--------------------------------------------------------------------------------------------------------------------------------------------

19.

From c3Method1 of class C3, it possible to call the methods of its base class C1 public and protected methods c1Method1 and c1Method2. It is not possible to call the private method c1Method3 of class C1 from the c3Method1 of class C3 since c3Method1 is private.

20.

From c3Method2 of class C3, it possible to call the methods of its base class C1 public and protected methods c1Method1 and c1Method2. It is not possible to call the private method c1Method3 of class C1 from the c3Method2 of class C3 since c3Method1 is private.

21.

From c3Method3 of class C3, it possible to call the methods of its base class C1 public and protected methods c1Method1 and c1Method2. It is not possible to call the private method c1Method3 of class C1 from the c3Method3 of class C3 since c3Method1 is private.

--------------------------------------------------------------------------------------------------------------------------------------------

22.

Since C1 is parent class, C2 is a child class of parent class C1 .

Parent class cannot access the child class methods. But the child class can access its parent class public and protected methods. Therefore, c1Method1 of Class C1 cannot access the methods of class C2.

23.

Since C1 is parent class, C2 is a child class of parent class C1.

Parent class cannot access the child class methods. But the child class can access its parent class public and protected methods. Therefore, c1Method2 of Class C1 cannot access the methods of class C2.

24.

Since C1 is parent class, C2 is a child class of parent class C1.

Parent class cannot access the child class methods. But the child class can access its parent class public and protected methods. Therefore, c1Method3 of Class C1 cannot access the methods of class C2.

--------------------------------------------------------------------------------------------------------------------------------------------

25

The class C1 contains three instance variables x1, x2 and x3.

The object of C1 class can encapsulate three instance variables.

Class C1

public

protected

private

Object

x1

x2

x3

26

The class C2 inherits the public and protected members of its parent class C1.

The class C2 contains three its own instance members called as y1, y2 and y3

and inherited instance variables of class C1 are called as x1 and x2.

So total 5 instance variables can be encapsulate into the object of C2

Class C2

public

protected

private

public of C1

protected of C1

Object

y1

y2

y3

x1

x2

27

The class C3 inherits the public and protected members of its parent class C1 and C2.

The class C3 contains three its own instance members called as z1, z2 and z3

Inherited instance variables of class C1 are called as x1 and x2 and.

And inherited instance variables of class C2 are called as y1 and y2.

So total 7 instance variables can be encapsulate into the object of C3

Class C3

public

protected

private

public of C1

protected of C1

Public of C2

Protected of C2

Object

z1

z2

z3

x1

x2

y1

y2

Hope this helps you..

Class C1

public

protected

private

C1Method1()

Yes

Yes

Yes

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote