ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 


 

Company >> BearingPoint >> BearingPoint Questions
 
 BearingPoint interview questions  BearingPoint Interview Questions (2)
 
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
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com