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


Please Help Members By Posting Answers For Below Questions

What is string args [] in java?

787


How do you break a loop?

781


What is the use of string and stringbuffer?

786


What is a Transient Object?

849


Give few examples of final classes defined in Java API?

925


What are the disadvantages of using inner classes?

788


What is isa relationship?

766


How to sort double array in java?

797


Write a java program to check if a number is prime or not?

776


What do you mean by of string::valueof expression in java 8?

764


What is string manipulation?

724


What is the difference between break and continue statements?

820


Can we declare a class as static?

818


What do you mean by local variable and instance variable?

739


Difference between static synchronization vs. Instance synchronization?

841