You are here: Home / Topics / Page / 4

Program to explain Generic class with Wildcard in Java

Filed under: Java on 2024-04-13 09:06:42
// Program to explain Generic class with Wildcard.class  GenericStats<T extends Number> {T[ ]  nums;   GenericStats(T[ ]  o) { nums = o;}double average() { double sum = 0.0; for(int i=0; i < nums.length; i++) {  sum += nums[ i

Program 2 to explain Generic method with Bounded type in Java

Filed under: Java on 2024-04-12 18:38:35
// Program to explain Generic method with Bounded type.// GenericType<? extends upperBoundType>import java.util.ArrayList;import java.util.List;public class  GenericTest10 {public static double getAverage(List<? extends Number> numberList) { double total = 0.0; f

Program to explain Generic Method in Java

Filed under: Java on 2024-04-12 18:37:56
// Program to explain Generic Method.public class  GenericTest7 {// generic method printArraypublic static <T> void printArray(T[ ] inputArray) { // display array elements for (T element : inputArray)  System.out.printf("%s  ", element); System.out.print

Program to explain Simple Generic class in Java

Filed under: Java on 2024-04-12 18:32:56
// Program to explain Simple Generic class.class   A<T> {T ob;A(T o) { ob = o;}T getob() { return ob;}void showType() { System.out.println("Type of T is " + ob.getClass().getName());}}public class  GenericTest1{public static void main(String args[ ]