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 toarray method in java?
Explain what is encapsulation?
What is fundamental datatype?
What is java util hashmap?
What is bigger kb or mb?
What is a arraylist in java?
Explain a few methods of overloading best practices in java?
What is meant by string is immutable?
What are computer functions?
Difference between character constant and string constant in java ?
How dead lock situation occurs in java and how you can identify it?
What are the drawbacks of singleton class?
What is the exact difference in between unicast and multicast object? Where we will use?
What is string args [] in java?
How variables are declared?