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
Explain what is encapsulation?
Can a static class have a constructor?
Explain when we should make an instance variable private.
Describe the Big-O Notation.
how to run ecllipse with jettyserver for windows environment using batch file
Can we able to pass objects as an arguments in java?
Difference between current previous versions of Java?
What is a dot notation?
What are the advantages of unicode?
What is a class reference?
How many wrapper classes are there in java?
What is the maximum size of hashmap in java?
Difference between process and thread?
How to sort an unsorted array in java?
Where can I find jdk in my computer?