What is the is a and has a relation ship in oops concept in
java?
Answer Posted / sandya
The relationships are the structure of the object. has-a
relationship can be described in Java code as member fields.
is-a relationship can be described in Java keyword extends.
The is-a relationship has an inheritance feature (like
"extends" or "implements") and has-a relationship has an
encapsulation feature (like private or protected modifier
used before each member field or method).
Let's look at one example. Translate the following perfect
sentences into Java code.
1. Pizza is a food. A Pizza has ingredients, a cost, and
a price.
public class Pizza extends Food //is-a relationship
{
int ingredients;//has-a relationship
double cost;
double price;
....
}
| Is This Answer Correct ? | 148 Yes | 13 No |
Post New Answer View All Answers
What is the purpose of default constructor?
What are the basic control structures?
How a variable is stored in memory?
How many threads can java run?
What are use cases?
Why collection doesn’t extend cloneable and serializable interfaces?
Do you know how to reverse string in java?
What do you mean by platform independence of Java?
What is regex java?
What is main method?
Is java still relevant?
Define interface in java?
Why java is call by value?
What is try-with-resources in java?
What does jre stand for?