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 thatdirectly 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 overmany classes rather than having its own class.
Loose coupling is achieved by means of a design that promotes single-responsibility and
separation ofconcerns.
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 thanother concrete classes, and any class can be on the other end of that communication
simply by implementingthe interface.
E: Not enough information regarding SuperX’ to determine the level of cohesion.



Leave a Reply 4

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


Tim

Tim

Should be A B E.

D seems not correct, for they are actually tightly coupled.

jalex

jalex

The answer is B, D, E…..A cannot be because Class SuperX has class Z but it does not mean that a subclass from SuperX will have classZ, and D is correct because the variable is public on Util so X is coupled to Util.

Luiz

Luiz

Loosely coupled is different from tight coupled