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 string args [] in java?
How do you break a loop?
What is the use of string and stringbuffer?
What is a Transient Object?
Give few examples of final classes defined in Java API?
What are the disadvantages of using inner classes?
What is isa relationship?
How to sort double array in java?
Write a java program to check if a number is prime or not?
What do you mean by of string::valueof expression in java 8?
What is string manipulation?
What is the difference between break and continue statements?
Can we declare a class as static?
What do you mean by local variable and instance variable?
Difference between static synchronization vs. Instance synchronization?