Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


harikrishna
core java - Use of polymorphism in object oriented programming
2 Answer(s)      6 years and 9 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?


Advertisement
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 Добовляйтесь в группу "МАЙНКРАФТА" Будьте участниками Группы Помогаите нам и себе Наша группа https://vk.com/club60851464 Есть свой сервер! Хорошая атмосфера. [Хороши спавн зделаный в ручную] Добрая администрация, хорошие игроки адекватные! Ждём вас у нас в группе и на сервере!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 Tutorials/Questions & Answers:
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
Advertisements
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
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
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
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
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
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
Object-Oriented programming - Java Beginners
Object-Oriented programming  Write a program to display the names and salaries of 5 employees.Make use of a class and an array.The salary of each employee should increase by 5% and displayed back.  Hi friend, Code
Object Oriented
Object Oriented  C++ is Purely object oriented or not .Then why java called purely object oriented
Object Oriented Programming in Java
OOPS acronym for Object Oriented Programming is a model or concept that works around objects and data. Programming language like Java that follow the OOP... of a class. For a language to be an Object Oriented Programming Language, it must
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
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  
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
An Overview of Java      Java is a programming language      Java is Object Oriented Programming
; Java as a programming language Java is an Object oriented application programming language developed by Sun Microsystems. Java is a very...; Java as an Object Oriented Language In this section, we will discuss the OOPs
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
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
What is attribute oriented programming?
What is attribute oriented programming?  Hi, What is attribute oriented programming? Thanks
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 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
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
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 to Java
Java is an open source object oriented programming language... like encapsulation, inheritance and polymorphism. A java program is always saved..., Mike Sheridan under James Goslings decided to develop a programming language
Java run time polymorphism
Java run time polymorphism  What is run-time polymorphism or dynamic method dispatch
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
Object oriented program - Java Beginners
Object oriented program  Write a class called RaceCar.java that contains instance variables horsepower, weight, zeroTo60, and milesPerGal. The value.... Create an application class to get input from the user and use it to create two
 

 

 

DMCA.com