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
What is the intersection and union methods?
What super () does in java?
Describe how to implement singleton design pattern in struts.
Are arrays primitive data types?
Is string is a keyword in java?
How will you add panel to a frame?
Why there are some null interface in java? What does it mean?
Explain about procedural programming language or structured programming language and its features?
How to compare strings in java?
Is binary a low level language?
Explain different forms of polymorphism?
What is the difference in between cpp and java? Can u explain in detail?
What is finally and finalize in java?
Is null false in java?
What is floating data type?