Which three statements are true?

Given these facts about Java classes in an application:

– Class X is-a Class SuperX.

– Class SuperX has-a public reference to a Class Z.

– Class Y invokes public methods in Class Util.

– Class X uses public variables in Class Util.

Which three statements are true?

Given these facts about Java classes in an application:

– Class X is-a Class SuperX.

– Class SuperX has-a public reference to a Class Z.

– Class Y invokes public methods in Class Util.

– Class X uses public variables in Class Util.

Which three statements are true?

A.
Class X has-a Class Z.

B.
Class Util has weak encapsulation.

C.
Class Y demonstrates high cohesion.

D.
Class X is loosely coupled to Class Util.

E.
Class SuperX’s level of cohesion CANNOT be determined

Explanation:
B: Has class Util has both public methods and variables, it is an example of weak encapsulation.
Note:Inheritance is also sometimes said to provide “weak encapsulation,” because if you have code that directly uses a subclass, such as Apple, that code can be broken by changes to a superclass, such as Fruit. One of the ways to look at inheritance is that it allows subclass code to reuse superclass code. For example, if Apple doesn’t override a method defined in its superclass Fruit, Apple is in a sense reusing Fruit’s implementation of the method. But Apple only “weakly encapsulates” the Fruit code it is reusing, because changes to Fruit’s interface can break code that directly uses Apple.

D:
Note:Tight coupling is when a group of classes are highly dependent on one another.

This scenario arises when a class assumes too many responsibilities, or when one concern is spread over many classes rather than having its own class.

Loose coupling is achieved by means of a design that promotes single-responsibility and separation of concerns.

A loosely-coupled class can be consumed and tested independently of other (concrete) classes.

Interfaces are a powerful tool to use for decoupling. Classes can communicate through interfaces rather than other concrete classes, and any class can be on the other end of that communication simply by implementing the interface.
E: Not enough information regardingSuperX’to determine the level of cohesion.



Leave a Reply 4

Your email address will not be published. Required fields are marked *


Dylan

Dylan

A – If SuperX has a Z, then subclass X has it too.
B – If X is accessing public variables in Util, then Util has weak encapsulation.
E – Not enough info to determine SuperX’s level of cohesion.