Tuesday, 31 January 2017

Generic : GenericClassUsingInteger


class Data1<Integer>
{
    Integer i;
    public void add(Integer i)
    {
        this.i = i;
    }
    public Integer get()
    {
        return i;
    }
}
public class GenericClassUsingInteger {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.out.println("Passing integer to generic-type class");
       
        Data1<Integer> d1 = new Data1<>();
        d1.add(25);
       
        Data1<Integer> d2 = new Data1<>();
        d2.add(new Integer(25));
       
        System.out.println(d1.get());
        System.out.println(d2.get());
    }
}

No comments:

Post a Comment