Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java


Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

Polymorphism in Java
Previous Home Next

Polymorphism in java is a concept by which we can perform a single action by different ways. When two or more same statements having different meaning then it is called as polymorphism. Polymorphism is derived from 2 greek words: poly and morphs. The word "poly" means many and "morphs" means forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. There are two types of polymorphism in java: compile time polymorphism (static binding)and runtime polymorphism(dynamic binding). We can perform polymorphism in java by method overloading and method overriding. Method overloading is an example of static polymorphism, while method overriding is an example of dynamic polymorphism. Polymorphism means one name and many forms.

Types of Ploymorphism

  1. Method Overloading.
  2. Method Overriding.
  1. Method Overloading

    Method overloading means there are several methods present in a class having the same name but different types/order/number of parameters. When two or more methods of same name in a class, provided that there argument list or parameters are different. This concept is known as Method Overloading. Method overloading increases the readability of the program.

    Different ways to overload the method:

    1. By changing number of arguments
    2. Example:
      int sum(int a,int b);
      int sum(int a,int b,int c);
    3. By changing the data type
    4. Example:
      float sum(int a,float b);
      float sum(float a,int b);

      Rules for Method Overloading

      1. Overloading can take place in the same class or in its sub-class.
      2. Constructor in Java can be overloaded.
      3. Overloaded methods must have a different argument list.
      4. The parameters may differ in their type or number, or in both.
      5. They may have the same or different return types.
      6. It is also known as compile time polymorphism.

      Example :

      // Method Overloading by changing the no. of arguments
      class Calculation
      	void sum(int a,int b)
      	void sum(int a,int b,int c)
      	 public static void main(String args[])
      		Calculation obj=new Calculation();  

      output :


      Example :

      //Method Overloading by changing data type of argument
      class Calculation2
      	void sum(int a,int b)
      	void sum(double a,double b)
        public static void main(String args[])
      	Calculation2 obj=new Calculation2();  

      output :

      Previous Home Next