Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the significance of the concept of inheritance within the concept of obj

ID: 3822055 • Letter: W

Question

What is the significance of the concept of inheritance within the concept of object oriented programming? How does the concept of inheritance improve on the traditional programming model?
• Provide a programming problem in which inheritance should be used (You do not need to write codes for this discussion. Instead, describe the programming problem and explain why inheritance should be used).
• Research the concept of Polymorphism and, again, provide a programming problem in which polymorphism should be used

Explanation / Answer

Inheritance

Inheritance is a mechanism of acquiring the features and behaviors of a class by another class. Inheritance enables new classes to receive or inherit the properties and methods of existing classes. The relationships of objects or classes through inheritance give rise to a hierarchy. Inheritance derive classes using existing classes which provides reusablity. The existing classes remain unchanged and thdevelopment time of the programming is reduced by reusability.

class Super{

//code

}

class Sub extends Super{

//code

}

Here "super" is called as the base class or parent class and "sub" is called the child or derived class which gets its properties from its parent classs.The child class sub inherit the properties in a clear instance methods and fields of its parent class.

Now,let us consider an example which briefly shows the meaning of inheritance relationship.

public class Fruit{

}

public class Mango extends Fruit{

}

public class Grapes extends Fruit{

}

From the above example, Grapes and Mango are two child classes which derives properties from its parent class Fruit.

POLYMORPHISM:

It is in general defined as an ability of an object to take many forms.

class A:

private int a,b,c

void Sum()

{

a=37;

b=42;

c=a+b;

}

A1:

float f1,f2,f3;

void Sum()

{

f1=1.3f;

f2=2.5f;

f3=f1+f2;

}

A2:

char c1,c2,c3;

void Sum(){

c1='A';

c2='B';

c3=c1+c2;

}

In the above diagram,the sum method which is present in class A is the original form and the sum() method which are present in A1 and A2 are called overridden form.By this we can say that sum method is originally implemented in original form and can be implemented in many forms as shown above.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote