0% found this document useful (0 votes)
24 views1 page

Lab 4 Java

Polymorphism provides three main advantages: 1) Code reusability through inheritance, which allows child classes to automatically access code stored in parent classes rather than copying and pasting code. This prevents issues with duplicate or incorrect code. 2) Increased maintainability and extendability since code is structured in a hierarchical class structure, making it easier to debug, modify, and add new features. 3) Reduced complexity since programming tasks can be divided into separate classes that each handle different parts of an overall problem, rather than needing to build a single monolithic class.

Uploaded by

Fadzli Razali
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

Lab 4 Java

Polymorphism provides three main advantages: 1) Code reusability through inheritance, which allows child classes to automatically access code stored in parent classes rather than copying and pasting code. This prevents issues with duplicate or incorrect code. 2) Increased maintainability and extendability since code is structured in a hierarchical class structure, making it easier to debug, modify, and add new features. 3) Reduced complexity since programming tasks can be divided into separate classes that each handle different parts of an overall problem, rather than needing to build a single monolithic class.

Uploaded by

Fadzli Razali
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Question 4

Explain the advanteges of using polymorphism


1) Code re-usability: Using the code written somewhere in program. Until C, Code re-usability can be achieved using making it into an function. Then the function would be called whenever it is needed. But in OOP, function is wrapped up into class. Required code cannot simply be called. Hence came the concept of Inheritance. Whenever any code stored in other class is needed, we make child class and child class automatically has the required code via - Inheritance. To beat Code re-usability many point that required code can simply be "Copied" and "Pasted". This certainly solves the need but leads to Wiki-Long and repetitive code. What if later on repeated code is incorrect? Even "Search and Replace" feature would not help. 2) Maintainability - Extendability Using Inheritance makes the code structured. Father - Child - Child and so on. Things are defined at appropriate level class. Thus the code looks neat. This means real easy debugging, easy to modify and easy to add new features. 3) Reduction in complexity Now thats what everyone wants to hear. Programming is too complex!! Inheritance can surely lower the bar. Take an example. You need to plan a trip. Now Lets review the idea to trip process. Think of a place Approach the people and talk about plan. Check who wants to come Everyone sits together and decides of mode of transport Meanwhile the others figure out route Finally exact time of departure is decided

Analyzing the above process, Initially the abstract idea is decided Once it is finalized, More details are added at later stage. We cannot directly build a complete detailed class. Task is divided into parts. We have different classes to do different jobs.

You might also like