Ask a question from expert

Ask now

Assignment on Explaining Polymorphism

11 Pages1647 Words313 Views
   

Added on  2019-09-20

Assignment on Explaining Polymorphism

   Added on 2019-09-20

BookmarkShareRelated Documents
Running Case: OBJECT-ORIENTED APPLICATIONSIndividual_Assignment_4(Object-Oriented Applications)Student Name: Student ID: Course Name: Course ID:Faculty Name: University Name:
Assignment on Explaining Polymorphism_1
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 will learn later. Object oriented programming maps the problem into real world concepts and then find the solution 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 of objects of similar functionalities.For example Pen is a class which represents a community or caste with common functionalities i.e. to write 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.Encapsulation 2.Polymorphism3.Inheritance 4.AbstractionPolymorphism : Polymorphism as it name explains many, hence polymorphism mean many forms. In object orientation polymorphism 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 Overloading Method overloading is achieved is achieved by putting same name for the methods and changing its 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){
Assignment on Explaining Polymorphism_2
OBJECT-ORIENTED APPLICATIONS2// some code}This is how we can define multiple methods with same to add numbers. This is done to improve the readability of code.Method overloading can be achieved by using the same syntax of all the methods with different data 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 compiler only. The diagrammatic representation of method overloading is shown below : The above diagram states the example of overloading. Here the word manager is overloaded. The same manager word can be used for various roles like General Manager, Product Manager, Project Manager, 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 new functionalities for any method that is inherited from Parent class, this is known as method overriding (Holzle et al, 1991).Method overriding is example of dynamic or runtime polymorphism because method binding between method calling and method definition is done by the JVM not by the compiler when the object is created.The advantage of method overriding is code reusability, the child class method can use the parent class method or functionalities and enhance them, this increases the readability of the code too. Suppose for example,Class Animal
Assignment on Explaining Polymorphism_3
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 animal class. 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 )
Assignment on Explaining Polymorphism_4

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Object Oriented Programming with C#
|6
|690
|365

Research on Object Oriented Language
|2
|647
|530

Object Oriented Programming in Aviation Airlines
|8
|1302
|148

Unit 20 Advanced Programming - Assignment
|31
|3536
|337

Object Oriented Programming: Inheritance, Encapsulation, Polymorphism
|11
|1451
|340

Class And objectives in Java Laguage
|13
|1461
|20