What is the is a and has a relation ship in oops concept in
java?
Answer Posted / 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 |
Post New Answer View All Answers
What is variable and constant explain with example?
Mention the default values of all the elements of an array defined as an instance variable.
What does math floor () do?
What is a lock or purpose of locks in java?
What does i ++ mean in Java?
What are the differences between stringbuffer and stringbuilder?
What is a instance variable in java?
How can we make a class singleton?
Does java initialize arrays to zero?
What is difference between throw and throws ?
What is lambda expression in java?
What is append function?
How can you read an integer value from the keyword when the application is runtime in java? example?
What are variable arguments or varargs?
What is class level lock ?