Question: Write a generic method, addNumber that uses a formal parameter type that extends from Number and returns a type that extends from Number. The method
Write a generic method, "addNumber" that uses a formal parameter type that extends from "Number" and returns a type that extends from "Number". The method adds two objects of the same type and returns an object of that type. The methods signature is as follows. public static T addNumber(T num1, T num2) Create a class, "GenericTest" that contains the "addNumber" and "main" methods. The "main" method performs the following.
1. Creates two "Double" objects, adds them and displays the results
2. Creates two "Integer" objects, adds them and displays the results
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
