| Back to Questions Page |
| Question |
What is the is a and has a relation ship in oops concept in
java? |
Rank |
Answer Posted By |
|
Interview Question Submitted By :: Sandya |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer |
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;
....
}
 |
4 | Sandya |
| |
| |
| Answer |
Ya correct there is relation ship. that is the main concpt
in java  |
0 | Gopid123 |
| |
| |
| Answer |
is a nothing but inheritance and has a nothing but extends  |
0 | Guest |
| |
| |
|
|
| |
| Answer |
OOOOOO!NOooooooooo.
is a relationship is (inheritence)
has a relationship is (composition or Assocation)
Example:
Has a relation
public class Address
{
String street;
String city;
.......
}
public class Person
{
String name;
Address address; //has a relationship
}  |
2 | Raghava |
| |
| |
| Answer |
Yea you right.
is-a represent the inheritence
and
has-a represents the delegation/association
for example
Chair is a type of Furniture
and
Furniture has a relationship with chair  |
0 | Vashisht Rakesh |
| |
| |
|
| |
|
Back to Questions Page |