What is the is a and has a relation ship in oops concept in
java?

Answers were Sorted based on User's Feedback



What is the is a and has a relation ship in oops concept in java?..

Answer / 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

What is the is a and has a relation ship in oops concept in java?..

Answer / raghava

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
}

Is This Answer Correct ?    82 Yes 6 No

What is the is a and has a relation ship in oops concept in java?..

Answer / vashisht rakesh

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

Is This Answer Correct ?    33 Yes 5 No

What is the is a and has a relation ship in oops concept in java?..

Answer / kishor patil

Inheritance defines the relationship is-a(also called the
superclass-subclass relationship) between a superclass and
it's subclasses. This means that an object of a subclass
is-a superclass object,and can be used wherever an object
the of superclass can be used.

For EX-Suppose person is a superclass of Teacher
class,Driver class,Engineer class.

Here we can say every Teacher is person,Every Driver is
a person,And Every Engineer is a person ,but vice -versa
not true i.e Every person can not be teacher or driver or
Engineer.


Aggregation Defines the relationship has-a(also called
whole-part relatioship)between an instance of class and
it's constituents(also called parts).Aggregation comprises
the usage of objects.

We can say that a composite object built from the
constituent objects that are its parts .


For EX- Vehical is class.

vehical has a wheel,
vehical has a engine,
vehical has a stearing ,
vehical has a gear.


means vehical has a parts like
wheel,engine ,stearing ,gear.

Is This Answer Correct ?    24 Yes 2 No

What is the is a and has a relation ship in oops concept in java?..

Answer / b venkat reddy

The "is a" relationship is expressed with inheritance and
"has a" relationship expressed with composition.


Both inheritance and composition allow u to place sub-objects inside your new class.Two main techniques to code reuse are inheritance and composition.

Ex.: IS A ===>> house IS A building

class House {
.....
}
class Building extends House{
......
}

Ex.:HAS A ===>> house HAS A bathroom

class House {
Bathroom b = new Bathroom();
}

Is This Answer Correct ?    22 Yes 5 No

What is the is a and has a relation ship in oops concept in java?..

Answer / gopid123

Ya correct there is relation ship. that is the main concpt
in java

Is This Answer Correct ?    37 Yes 34 No

What is the is a and has a relation ship in oops concept in java?..

Answer / crosseyed

Answer 4 and Answer 1 might both give simialr outputs but
their adoption depends on the size of a persons analytic
universe. And answer 4 is the better way to solve most
problems because it is easier to write and modify.

Much code is part of a system describing just the tiny part
of the universe an enterprise wishes to describe. If that
enterprise is a single product pizza manufacturer then for
such an enterprise the relevant universe is only pizza and
no other category of food exists to be extended in software
(profitably) by the manufacturer that is not some form of
pizza. The software engineer might wish to be a
nomenclature trailblazer, extending his code ever outward
in describing the whole universe of food. But pizza makers
are far too stingy to pay for trailblazing.

On the other hand if the enterprise is a supermarket then
the class food might (but shouldn't) be seperated from
classes for school supplies, medications and so on and
extended to include types of food. But is bagel pizza
really pizza? What about pizza crusts? Pizza crusts with
tomato sauce but no other topping? What about club soda
marketed as a cleaning supply? What about mouthwash
marketed as a cure for an alcoholics DT's? Where will we
draw the lines?

If in either case you were to use inventoryItem as a class
and add only properties sufficent to perform an inventory
you may not be trailblazing the catalogue of the worlds
foods and other stuff, but you will have much more easily
written and modified code.

World class descriptions of the universe may be a grand
ideal - but sometimes all you need do is count the number
of pepperoni pizzas! Describe only what is needed for a
purpose. Tofu, after all, can taste like fish or foul and
even Plato might not be able to categorize all its
variations depending on his ability to percieve spices!
But a store has only to tell how much of the various
packages they own sells best and how many of those are left.

Is This Answer Correct ?    3 Yes 10 No

What is the is a and has a relation ship in oops concept in java?..

Answer / yogeshwar

is a
Relationship between a Class and its object.
Eg.
Class Car { ... }

Car maruti800=new Car();

here maruti800 is a car.
Relationship between Car and maruti800 ==> is a

the Person and Address is a suitable example for has a

Is This Answer Correct ?    2 Yes 11 No

What is the is a and has a relation ship in oops concept in java?..

Answer / guest

is a nothing but inheritance and has a nothing but extends

Is This Answer Correct ?    15 Yes 103 No

Post New Answer

More Core Java Interview Questions

What are accessor methods in java?

0 Answers  


When do you call copy constructor?

0 Answers   Tavant Technologies, Virtusa,


Describe the syntax of multiple inheritance? When do we use such an inheritance?

0 Answers   Fidelity,


if u open login & logout ,how can udisplay the timelogin & logout members ?

0 Answers   Virtusa,


Is it possible to write JAVA program without including any of the packages,such as "import java.io.*"; bcoz I instantly wrote a code without "import..." statement and runned the program on command Line & it worked. the code is: class Person { String name; int age; Person(String s,int a) { name = s; age = a; } accept() { System.out.println(name+"Hi!!!!!"); System.out.println(age); } } class Demo { public static void main(Strings args[])throws IOException { String name = args[0]; int age = Integer.parseInt(args[1]); Person p = new Person(name,age); p.accept(); } }

3 Answers  






Write an algorithm for quick sort?

0 Answers   Virtusa,


What classes of exceptions may be thrown by a throw statement?

0 Answers  


What is a short in java?

0 Answers  


what is d difference between deep cloning and shallow cloning in core java?

3 Answers   Satyam,


can rmi and corba based applications interact ?

0 Answers  


what is the difference between multitasking and multithreading?

21 Answers   TCS,


What is void data type?

0 Answers  


Categories