Assignment on Explaining Polymorphism

Added on - 20 Sep 2019

  • 11


  • 1647


  • 95


  • 0


Showing pages 1 to 4 of 11 pages
Running Case: OBJECT-ORIENTED APPLICATIONSIndividual_Assignment_4(Object-Oriented Applications)Student Name:Student ID:Course Name:Course ID:Faculty Name:University Name:
OBJECT-ORIENTED APPLICATIONS1Object Orientation.Object orientation is basically a programming paradigm that works on the concept of real world entities(Banerjee et al, 1987). It provides various concepts like classes, objects and many more which we willlearn later. Object oriented programming maps the problem into real world concepts and then find thesolution to it implementing the OOPs concepts and principles.In OOPs object is a real world entity that has some property and behavior where as a Class is group ofobjects of similar functionalities.For example Pen is a class which represents a community or caste with common functionalities i.e. towrite whereas Reynolds and Parker are objects which has some different properties like name, color,shape etc. and functionalities as already said writing.There are four principles of OOPs (Booch, 2006):1.Encapsulation2.Polymorphism3.Inheritance4.AbstractionPolymorphism :Polymorphism as it name explains many, hence polymorphism mean many forms. In object orientationpolymorphism means a way of performing one task by various ways.For example,if we need to start a bike we can do it by kick, by self-start or by pushing it.In object orientation polymorphism is of two types :1.Static or Compile time Polymorphism :Method OverloadingMethod overloading is achieved is achieved by putting same name for the methods and changingits arguments. If we have to perform the same task by multiple ways we do so.For example we have to add numbers.We can do so by,public int add (int a, int b){// some code}public double add (double a, double b){// some code}public long add (long a, long b){
OBJECT-ORIENTED APPLICATIONS2// some code}This is how we can define multiple methods with same to add numbers. This is done to improvethe readability of code.Method overloading can be achieved by using the same syntax of all the methods with differentdata types as arguments or numbers of the arguments.Method overloading is not achieved by changing the return type of the methods.Technically, it is an example of the static or compile time polymorphism because method bindingbetween the method calling and the method definition happens at complete time by the compileronly.The diagrammatic representation of method overloading is shown below :The above diagram states the example of overloading. Here the word manager is overloaded. Thesame manager word can be used for various roles like General Manager, Product Manager, ProjectManager, etc. The word manager is overloaded here.2.Dynamic or runtime polymorphism : Method Overriding :Method overriding in java is possible by Inheritance. When a child class method defines a newfunctionalities for any method that is inherited from Parent class, this is known as methodoverriding (Holzle et al, 1991).Method overriding is example of dynamic or runtime polymorphism because method bindingbetween method calling and method definition is done by the JVM not by the compiler when theobject is created.The advantage of method overriding is code reusability, the child class method can use the parentclass method or functionalities and enhance them, this increases the readability of the code too.Suppose for example,Class Animal
OBJECT-ORIENTED APPLICATIONS3{Public void eat (){// some code}}Class Dog extends Animal{Public void eat (){// some modified code}}The above diagram shows how the dog has overridden the eat () functionalities of the animalclass. The dog has changed the functionality i.e. overridden.Encapsulation :Encapsulation in java is generally a technique to bind or wrap the data fields and the methods together(Kniesel & Theisen, 2001). The data binding is done so that the any data needed by outsiders can only getit through the methods. Suppose that,We have a class with some fields,Class Employee{private int id;private int salary;public void setId ( int id )
You’re reading a preview

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Download This Document