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
Does java initialize arrays to zero?
What are the two parts of a conditional statement?
when to use ArrayList and when to use HashMap in webApplication.
What is the console in java?
Does java support function overloading, pointers, structures, unions or linked lists?
How many types of flags are there?
Which class is used by server applications to obtain a port and listen for client requests?
Explain about oops concepts.
Does java have extension methods?
Can we have two methods in a class with the same name?
Mention a package that is used for linked list class in java.
Can you give few examples of final classes defined in java api?
Is null a string?
How to reverse a string in java?
What is internal variable?