When you subclass a vector can you put primitives in it? (I know vectors only hold objects)Can you even subclass a Vector? public class Subvector extends Vector int i=5; //does error occur here? public static void main(String args[ ]) Subvector sv = new Subvector( ) //does error occur here? System.out.println(sv.i) //does error occur here? Thanks in Advance Best Regards Edmund
Didn't we go through this exact question just a short while ago? The answer is no. All your example did was add a single int to a Vector object. The Vector would still not be able to hold more than one int. You could create a whole new class call IntCollection based on the Collection interface that does hold ints in an array. As far as your questions about when an error occurs, you can download the Java J2SE from Sun and try it yourself. [This message has been edited by Thomas Paul (edited April 26, 2001).]
hi, if your criteria is only to put integers in vector class then use wrapper class in which you can give primitive values accordingly. later on you can conver object to primitive or primitive to objects accordingly.