Java OCA OCP Practice Question 2366

Question

Given the following code, select the correct options:

class Shape {}
class Square extends Shape {}
interface Printable {}
class Sun implements Printable {
    Square Shape;
}
a   Square IS-A Printable.
b   Square HAS-A Shape.
c   Sun HAS-A Shape.
d   Sun HAS-A Square.
e  Shape HAS-A Printable.
f  Sun IS-A Abx.
g   Square IS-A Abx.


d, g

Note

Option (a) is incorrect.

Classes Square and Printable are unrelated.

Option (b) is incorrect.

Class Square extends class Shape; it doesn't define a variable of type Shape.

The correct relationship here would be Square IS-A Shape.

Option (c) is incorrect.

Class Sun defines a variable of type Square.

So the correct relation would be Sun HAS-A Square.

The IS-A and HAS-A relationships don't reflect the names of the variables.

Option (d) is correct.

Class Sun defines a variable of type Square, so the relationship Sun HAS-A Square is correct.

In option (e), class Shape doesn't define any variable of type Printable, so this relationship is incorrect.

In option (f), class Sun doesn't extend class Shape, so this relationship is incorrect.

In option (g), class Square extends class Shape, so this relationship is correct.




PreviousNext

Related