-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerixMain.java
More file actions
41 lines (32 loc) · 1007 Bytes
/
Copy pathGenerixMain.java
File metadata and controls
41 lines (32 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package genrx;
/* 1. The mechanism is called GENERIX in java.
* 2. This is use to use different data type for different memory allocation for object
* but every object has same variable name.
* */
class D<T>//T is a data type variable (which is actually a class variable)
{
private T firstvalue; //Here T belongs to Wrapper class contains Integer, Double, Character etc.
private T secondvalue;
D(T f1 , T f2)//Parameterised constructor (constructor with argument)
{
/* To store the value here AUTOBOXING & AUTOUNBOXING occurred.
* */
firstvalue = f1;
secondvalue = f2;
}
void display()
{
System.out.println("First Value is = " + firstvalue);
System.out.println("Second Value is = " + secondvalue);
}
}
public class GenerixMain
{
public static void main(String[] args)
{
D<Integer> ob1 = new D<Integer>(5,10);//Creating Generic class object with Integer type class
D<String> ob2 = new D<String>("HELLO","HI");
ob1.display();
ob2.display();
}
}