Home Answers Viewqa Java-Interview-Questions core java - Use of polymorphism in object oriented programming

 
 


harikrishna
core java - Use of polymorphism in object oriented programming
2 Answer(s)      5 years and 3 months ago
Posted in : Java Interview Questions

Hi all, I am digging for an example of polymorphism in object orient programming. Can anyone please help?

View Answers

February 25, 2008 at 5:07 PM


Use of polymorphism in object orient programming ? using Overloading and Overriding Concept

Polymorphism
It is a basic feature in OOP?s Strategy of programming emulated or being followed by high-level languages .
In java it states using of one single interface with a set of actions that is like one name may be referred to different functionality .

For example in creating a java program we create method
void Amount( )
{
-----
-----
}

Amount (int xyz)
{
---
---
}
Amount(int cat)
{
}

Now see carefully here in the small brackets of same method I have assigned three different?int amt, int xyz, int cat? parameters
(parameters are value data like that we assign in method)
this is called Overloading

And in case of same parameters it is said Overriding.

See In both cases method ?Amount()? is being more than one time and this what above definition say ?using of one single interface with a set of actions?.

For further details with examples concerning Encapsulation, Inheritance and Polymorphism chech undersigned URL.

http://www.roseindia.net/java/learn-java-in-a-day/oops.shtml


BaadshahKhan

February 25, 2008 at 6:52 PM


What is polymorphism?what is the exactly use of it?how we can use polymorphism in object orient programming.

Polymorphism :-

Polymorphism means the ability to take more than one form. Polymorphism means 'any forms.' In OOP, it refers to the capability of objects to react differently for the same method.

In OOP methodoverloading refers to the capability of objects to react differently for the same method. Polymorphism can be implemented in Java language in form of multiple methods having the same method name. Java code uses a late-binding for supporting polymorphism, the method which is invoked is decided at runtime.

In polymorphism by using a same function name with the different signature we can perform the multiple task this is called method overloading & using a same function name with the same signature we can extend the functionality of the superclass functions according to our requirement.

In java Polymorphism can be used in two ways :

1. Method Overloading

2. Method Overriding

1. Method Overloading :-
Overloaded methods are methods have the same name, but different argument lists.
Overloaded methods have the same names but different argument lists. The arguments may differ in type or number, or both. However, the return types of overloaded methods can be the same or different.

An example of the method overloading is given below:

class methodOverloading{
int add( int a,int b)
{
return(a+b);
}

float add(float a,float b)
{
return(a+b);
}
double add( int a, double b,double c)
{
return(a+b+c);
}
}
class mainClass extends methodOverloading
{
public static void main( String arr[] )
{
mainClass temp = new mainClass();
System.out.println(temp.add(10,20));
System.out.println(temp.add(1.5f,2.3f));
System.out.println(temp.add(10,20.4,25.6));
}
}

The output of the above program is given below:

30

3.8

56.0

2. Method Overriding :-
Overriding means when a subclass method has the same name, same return type, and same argument list as the superclass method.

class methodOverriding

{
String showMessage()
{
return("THIS IS SUPERCLASS METHOD");

}
}
class mainClass extends methodOverriding
{
public static void main( String arr[] )
{
String showMessage()
{
System.out.println("THIS IS SUBCLASS METHOD");
}
mainClass temp = new mainClass();
System.out.println(temp.showMessage());
}

}

The output of the above program is given below:

THIS IS SUBCLASS METHOD









Related Pages:
object oriented programming - Java Beginners
object oriented programming  sir, i read in the book tat object oriented program exhibits recurring structures. i want to know "what is meant by recurring structures?"  Hi Friend, Any structure to be occurred over
object oriented programming protocol
object oriented programming protocol  What is object oriented programming protocol? Is it different from objective c protocol programming?? Thanks
Object Oriented Programming in PHP
Object Oriented Programming in PHP  Hi, Which version of PHP supports OOPS. How can I learn Object Oriented Programming in PHP? Thanks
Is Java a pure object oriented language?
Is Java a pure object oriented language?   Hi, Is Java a pure object oriented language? thanks   Hi No, Java is an object oriented programming language but not purely a object oriented language. In OOPs programming
Object Oriented
Object Oriented  C++ is Purely object oriented or not .Then why java called purely object oriented
Java using Netbeans Object Oriented Programming
Java using Netbeans Object Oriented Programming   I am trying to make a program that uses a main class and a separate class with one public method and one private method. The main method in the main class asks the user for 2
Object Oriented Programming II
Object Oriented Programming II  Instructions: ->each class to be created must have encapsulated fields, setters and getters methods, and constructors Create a class named "Paper" with the following attributes
Polymorphism - Java Beginners
first then visit http://www.roseindia.net/java/master-java/java-object-oriented...Polymorphism  type of polymorphism  In Java polymorphism... Or we can also say that a polymorphism is possible in both state Static
core java code in object oriented manner - Java Interview Questions
core java code in object oriented manner   hi this is komali .i want small code for this question .its very urgent .please send me as soon as possible . i am waiting for code Sports Associations in India
What are the features and advantages of OBJECT ORIENTED PROGRAMMING?
What are the features and advantages of OBJECT ORIENTED PROGRAMMING?  What are the features and advantages of OBJECT ORIENTED PROGRAMMING
Java Training and Tutorials, Core Java Training
Java Training and Tutorials, Core Java Training       Core Java Training Java is a powerful object-oriented programming language with simple code
Object-Oriented Language: Java / APIs, Java OOPs
. Java is one of the useful Object Oriented programming language. Other Object..., Lasso, Perl 5,PHP5, VBScript, VBA etc. Java is popular object oriented programming...Java OOPs In this section we will learn Object Oriented (OOPs) Concepts 
Java Object
Java Object         Object is the basic entity of object oriented programming language. Object.../java-object-oriented-language.shtml  
java is pure object oriented
java is pure object oriented  java is pure object oriented or not.? reason.?   Java is not pure object oriented language because... are not object 2)It does not support operator overloading multiple inheritance. 3
Object-Oriented Programming
Java: Object-Oriented Programming Beyond OOP Here's an interesting article about going beyond OOP: The Next Move in Programming: A Conversation with Sun's Victoria Livschitz at java.sun.com/developer/technicalArticles/Interviews
java : object oriented
java : object oriented   (a) Write a class named CarRental... the user for the data needed for a rental and creates an object of the correct... an object of the correct type. Display the total rental fee
Core Java Topics
A First Java Program Object-Oriented Programming Classes and Objects... Core Java Topics Following are the topics, which are covered under Core Java. In the roseindia website for core java, programmer will find completed details
Core Java - Java Beginners
;Core JavaAn object oriented programming language that was introduced by Sun...Core Java  What is Java? I am looking for Core Java Training  Hi friendThe Core Java Technologies and application programming interface
dynamic polymorphism
dynamic polymorphism  give an example for dynamic polymorphism?   Dynamic polymorphism is where a class overrides a superclass method.... However, for a simple Java program that instantiates a series of objects
OOP
; Object Oriented Programming which was totally based on the real life entities... for Object oriented  Programming. Previously we used to follow... the object creation process, programmatically. Read more at : www.roseindia.net/java
Object Oriented concepts
OOP stands for Object Oriented Programming. This is a technique used to develop programs revolving around the real world entities. In OOPs programming... on the following links Object Oriented concepts
Introduction
the java applications and programs. OOP means Object Oriented Programming... Java as an Object Oriented Language   .... But in case of java,  it is a fully Object Oriented language because
Polymorphism - Java Beginners
Polymorphism  what is dynamic polymorphism? with example  Hi friend, Dynamic polymorphism is run time polymorphism. Thanks  The term static polymorphism is associated with overloaded methods because
fully object oriented language - Java Beginners
fully object oriented language  Is java is a fully object oriented language?if no,why?  Hi Friend, Java is not a fully object oriented... int,float which are not object 2)It does not support operator overloading
Core Java Training Topics
of programming and working knowledge of computer. Core Java... Programming Language Object-Oriented concepts... Core Java Training Topics      
runtime polymorphism - Development process
runtime polymorphism  how run time polymorphism is achieved  Hi Friend, The run-time polymorphism is basically the Method Overriding.Here super class reference is referring to subclass object and compiler does
Inheretance and polymorphism - Java Beginners
in Programming Exercise 1, you must derive the class Circle from the class... information on Java Visit to : http://www.roseindia.net/java/java-conversion/how
OOPs and Its Concepts in Java
;  Brief Introduction to OOP Object Oriented Programming... certain things common. In object oriented programming classes can inherit some common..., preparing a solution, coding and finally its maintenance. Java is a object
core java programming question
core java programming question  How to write a java program to list the customer names arrived to a restuarant on a particular date in alphabetical order with arguments as 1 filename yymmdd cust   Hi Friend, Try
Sitemap Core Java Tutorial Section
 | Ask Programming Questions and Discuss your Problems Core Java... Map | Business Software Services India Java Tutorial Section Core Java... | Java Swing Tutorials | Java Servlet Tutorials | J2EE Tutorials Core Java
core Java programming
core Java programming  Hi, Thanks for ur previous answers.... I need some of these answers also... Bharathi Indian Cuisine is a leading Indian...;TIME:HHMMSS;ITEM1:QTY:PRICE;ITEM2:PRICE2;] They are looking for a Java Program
core java - Development process
to : http://www.roseindia.net/java/master-java/java-object-oriented-language.shtml...core java  what is an Instanciation?  Hi friend, When we create object from a class, it is created on stack or on heap. The existance
What is attribute oriented programming?
What is attribute oriented programming?  Hi, What is attribute oriented programming? Thanks
Object in java - Java Beginners
/java/master-java/java-object-oriented-language.shtml http...Object in java  Hi deepak, I am new to java, can u tell me what... as a class object. Object: Object is the basic entity of object oriented
java object - Java Beginners
of objects. The primitive data type and keyword void is work as a class object. Object: Object is the basic entity of object oriented programming language...java object  i want a complete memory description of objects,methods
Core Java Programming - Java Beginners
Core Java Programming  Write a program in Java which initializes the starting date as your birthday and displays the date 90 days later in the format day name, month name, day, year   Hi friend, Code to solve
Core Java Programming - Java Beginners
Core Java Programming  Write a program in Java which generates a random number between 0 and 1. If the number generated is less than 0.5 then the program must print ?The Value is less than 0.5? and if the number generated
java object - Java Beginners
are stayed  Hi friend, Instance Variables (Non-static fields): In object oriented programming, objects store their individual states in the "non-static...java object  i want to where in the memory the java objects,local
Exp.4 Write any C++ programs to demonstrate multiple inheritance concept of an object oriented programming.
Exp.4 Write any C++ programs to demonstrate multiple inheritance concept of an object oriented programming.  (Aim:- The main aim of this experiment is reusability of code and getting idea about classifying objects , identifying
Core java interview question, object creation.
Core java interview question, object creation.  How can we restrict to create objects for more than five? That means i want only 5 objects, how to restrict to create 6th objects
Java Programming: Contents
Introduction to Programming Using Java, Fourth Edition Table of Contents...: Fundamental Building Blocks of Programs Section 5: Objects and Object-oriented...: Constructors and Object Initialization Section 3: Programming with Objects Section 4
Core Java Jobs at Rose India
Core Java Jobs at Rose India       This Core Java Job is unique among... with your job. You can work in Core Java and we will provide you training
core java
core java  what is difference between specifier and modifier? what is difference between code and data? what is difference between instance and object
Java run time polymorphism
Java run time polymorphism  What is run-time polymorphism or dynamic method dispatch
Java Training and Tutorials, Core Java Training
completion of object-oriented programming course in Java. You are aware...-oriented programming in Java and this is the strong reason for you to trust our... of object-oriented programming because all the chapters are further divided
programming
Java Constructor programming for single and double constructor  ... constructor,double parameter constor,and the now when we create a object of in this constructor he we tell the how much object we created in the no argument.single
Core Java Doubts - Java Beginners
Core Java Doubts  1)How to swap two numbers suppose a=5 b=10; without... - This is an important programming concept that assists in separating an object's state...); System.out.println(list); } } 3) Differences: a)A comparable object
CORE JAVA
CORE JAVA  Q)How to sort a Hash Table, if you pass an Employee Class Object in that First Name, Last Name, Middle Name based on last name how you sorting the Employee Class? Q)How to display the list variables in reverse
Object-Oriented Design - Overview
Java: Object-Oriented Design - Overview Encapsulation Article GetterEradicator It's a nice article about Encapsulation by Martin Fowler. Fowler is one.... It's rated number 3 in the JavaLobby poll of most useful Java books. It also has 4.5
core java
core java  1)How to short this {5, 4, 7, 8, 2, 0, 9} give me logic... max connection pool is 10 and all 10 connection object are being used, if same time a request is come that want connection object what will happened

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.