Java Overloaded Method To Print Array

Chapter: Inheritance Last Updated: 03-09-2016 11:58:58 UTC

Program:

            /* ............... START ............... */
                
public class JavaOverLoadPrintArray {

	public static void printArray(Integer[] inputArray) {
		for (Integer element : inputArray) {
			System.out.printf("%s ", element);
			System.out.println();
		}
	}

	public static void printArray(Double[] inputArray) {
		for (Double element : inputArray) {
			System.out.printf("%s ", element);
			System.out.println();
		}
	}

	public static void printArray(Character[] inputArray) {
		for (Character element : inputArray) {
			System.out.printf("%s ", element);
			System.out.println();
		}
	}

	public static void main(String args[]) {
		Integer[] integerArray = { 1, 2, 3, 4, 5, 6 };
		Double[] doubleArray = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 };
		Character[] characterArray = { 'H', 'E', 'L', 'L', 'O' };
		System.out.println("Array integerArray contains:");
		printArray(integerArray);
		System.out.println("\nArray doubleArray contains:");
		printArray(doubleArray);
		System.out.println("\nArray characterArray contains:");
		printArray(characterArray);
	}
}

                /* ............... END ............... */
        

Output

Array integerArray contains:
1 
2 
3 
4 
5 
6 

Array doubleArray contains:
1.1 
2.2 
3.3 
4.4 
5.5 
6.6 
7.7 

Array characterArray contains:
H 
E 
L 
L 
O 

Tags

Overloaded Method To Print Array, Inheritance, Java

Similar Programs Chapter Last Updated
Java Final Class Inheritance 02-08-2017
Java Final Method In Inheritance Inheritance 02-08-2017
Java Multilevel Hierarchical Inheritance Inheritance 01-08-2017
Java Super To Invoke Parent Class Method Inheritance 31-07-2017
Java Super To Invoke Parent Class Constructor Inheritance 30-07-2017
Static And Dynamic Binding In Java Inheritance 24-03-2017
Dynamic Method Dispatch In Java Example Inheritance 19-06-2016
Abstract Class In Java Example Inheritance 20-07-2016
Method Overriding In Java Example Inheritance 20-07-2016
Method Overloading In Java Example Inheritance 20-07-2016
Inheritance And Constructors In Java Inheritance 20-07-2016
Multilevel Inheritance In Java Example Inheritance 22-09-2018
Super() In Java Example Inheritance 14-07-2016
Inheritance In Java Example Inheritance 20-07-2016

1