-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGanericOOP.java
More file actions
45 lines (40 loc) · 858 Bytes
/
GanericOOP.java
File metadata and controls
45 lines (40 loc) · 858 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
42
43
44
45
import java.lang.*;
class Arithmatic<T>
{
public T No1;
public T No2;
Arithmatic(T a,T b)
{
No1=a;
No2=b;
}
public T Addition()
{
if((No1 instanceof Integer) && (No2 instanceof Integer))
{
return (T)(Integer)((Integer)No1+(Integer)No2);
}
else if((No1 instanceof Float) && (No2 instanceof Float))
{
return (T)(Float)((Float)No1+(Float)No2);
}
else if((No1 instanceof Double) && (No2 instanceof Double))
{
return (T)(Double)((Double)No1+(Double)No2);
}
else
{
return null;
}
}
}
class GenericOOP
{
public static void main(String arg[])
{
Arithmatic <Integer> obj=new Arithmatic<Integer>(10,11);
Integer iRet=0;
iRet=obj.Addition();
System.out.println("Addition is :"+iRet);
}
}