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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started