Multiple choice technology

Which two statements are true about has-a and is-a relationships? (Choose two.)

  1. Inheritance represents an is-a relationship

  2. Inheritance represents a has-a relationship

  3. Interfaces must be used when creating a has-a relationship

  4. Instance variables can be used when creating a has-a relationship.

Reveal answer Fill a bubble to check yourself
A,D Correct answer
Explanation

Inheritance in Java represents an 'is-a' relationship - a subclass 'is a' type of its superclass. Has-a relationships represent composition and are typically implemented using instance variables (e.g., a Car 'has an' Engine). Interfaces are not required for has-a relationships - you use composition directly with instance variables. Options A and D are both correct statements.