wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Vector Question!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Vector Question!!" Watch "Vector Question!!" New topic
Author

Vector Question!!

Edmund Chiang
Greenhorn

Joined: Apr 11, 2001
Posts: 17
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
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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).]


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
srinivasrao marri
Ranch Hand

Joined: Feb 13, 2001
Posts: 61
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Vector Question!!