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

Does java initialize arrays to zero?

511


What are the two parts of a conditional statement?

518


when to use ArrayList and when to use HashMap in webApplication.

3892


What is the console in java?

680


Does java support function overloading, pointers, structures, unions or linked lists?

608






How many types of flags are there?

525


Which class is used by server applications to obtain a port and listen for client requests?

494


Explain about oops concepts.

637


Does java have extension methods?

532


Can we have two methods in a class with the same name?

586


Mention a package that is used for linked list class in java.

529


Can you give few examples of final classes defined in java api?

566


Is null a string?

558


How to reverse a string in java?

526


What is internal variable?

540