You are here: Home / Topics / Program to explain that the Non-generic class can be the Super class of a Generic subclass

Program to explain that the Non-generic class can be the Super class of a Generic subclass

Filed under: Java on 2024-04-13 09:07:28

// Program to explain that the Non-generic class can be 
// the Super class of a Generic subclass.

class  NonGen 
{
int num;

NonGen(int i) 
{
 num = i;
}

int getNumber() 
{
 return num;
}
}

class  Gen<T> extends  NonGen 

T ob; 
  
Gen(T o, int i)
{
 super(i);
 ob = o; 


T getObject() 

 return ob; 



public class  GenericTest15

public static void main(String args[ ]) 

 Gen<String> w = new Gen<String>("NILS", 23);
  
 System.out.print(w.getObject() + " ");
 System.out.println(w.getNumber());

}


Output:

NILS  23


About Author:
J
Java Developer     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.