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 are the access modifiers available in java?

813


How do you remove duplicates in java?

749


What does it mean that strings are immutable?

870


How to make a write-only class in java?

797


Is java map thread safe?

705


What does function identity () do?

718


What is a dot notation?

762


What is meant by oops concept in java?

739


How to check if a list is sorted in java?

784


What languages are pass by reference?

781


What are the three parts of a lambda expression?

752


What does || mean in vectors?

704


What is gui programming?

721


When we serialize an object does the serialization mechanism saves its references too?

726


What classes of exceptions may be caught by a catch clause in java programming?

932