Number myNumber = new Number();
Long telephoneNo = new Long(27000134);
myNumber = telephoneNo;
Similarly in the case of method calls, a sub-class object can be passed as a parameter to a method, that is has a super-class object as a parameter in its defination.
public void someMethod(Number n){The above feature can also be implemented using generics as follows:
......
}
someMethod(new Integer(10));
someMethod(new Double(10.1));
Boxbox = new Box ();
box.add(new Integer(10));
box.add(new Double(10.1));
tutorials
No comments:
Post a Comment