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 the default value of float and double datatype in java?

519


What is an example of a boolean?

555


What is Classloader in Java?

624


Explain the difference between jvm and jre?

545


Difference between process and thread?

590






Why do I need to declare the type of a variable in java?

554


can rmi and corba based applications interact ?

651


What is java regex?

521


Java is Pass by Value or Pass by Reference?

610


Is finalize() similar to a destructor?

538


How do you reverse a word in java?

519


What is palindrome in java?

543


Is main an identifier?

534


What are multiple inheritances?

568


When a byte datatype is used?

555