JAVA GENERICS HACCKERANK


import java.io.IOException;
import java.lang.reflect.Method;

class Printer
{//object array will accept every data type and for using it we are using reflect method in language class
    public void printArray(Object arr[]){
        for(int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
       
    } 
   //Write your code here
 
}

public class Solution {


    public static void main( String args[] ) {
        Printer myPrinter = new Printer();
        Integer[] intArray = { 123 };
        String[] stringArray = {"Hello""World"};
        myPrinter.printArray(intArray);
        myPrinter.printArray(stringArray);
        int count = 0;

        for (Method method : Printer.class.getDeclaredMethods()) {
            String name = method.getName();

            if(name.equals("printArray"))
                count++;
        }

        if(count > 1)System.out.println("Method overloading is not allowed!");
      
    }
}

Comments

Popular posts from this blog

Solutions Of Practice Questions Dated 01-06-2022

CODEFORCES SPY DETECTED ROUND 713

Maximum Winning Score Geeks For Geeks