9B added
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
// write a program for Generic class
|
// write a program for Generic class 9A
|
||||||
public class GenericClass9A <T1, T2> {
|
public class GenericClass9A <T1, T2> {
|
||||||
public void display (T1 var1, T2 var2){
|
public void display (T1 var1, T2 var2){
|
||||||
System.out.println("Name: "+var1 + " ID: " + var2);
|
System.out.println("Name: "+var1 + " ID: " + var2);
|
||||||
|
|||||||
BIN
GenericClass9B.class
Normal file
BIN
GenericClass9B.class
Normal file
Binary file not shown.
20
GenericClass9B.java
Normal file
20
GenericClass9B.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
public class GenericClass9B<T> {
|
||||||
|
private T t;
|
||||||
|
|
||||||
|
public void add(T t){
|
||||||
|
this.t = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(){
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
GenericClass9B<Integer> rhombus = new GenericClass9B<Integer>();
|
||||||
|
GenericClass9B<Double> circle = new GenericClass9B<Double>();
|
||||||
|
rhombus.add(33);
|
||||||
|
circle.add(16.9);
|
||||||
|
System.out.println(rhombus.get());
|
||||||
|
System.out.println(circle.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
src/9B.png
Normal file
BIN
src/9B.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Reference in New Issue
Block a user