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
Can we have more than one package statement in source file ?
What is the difference between math floor and math round?
What is starvation?
Is singleton set an interval?
What are daemon Threads in java?
Can we declare a constructor as final?
What is core java used for?
What does 0 mean in boolean?
Can we use string in switch case in java?
Difference between arraylist and vector.
What is the main functionality of the remote reference layer?
Can we override private constructor in java?
What is the collection interface?
What are nested classes in java?
Explain the difference between comparator and comparable in java?