This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector Question!!

 
Edmund Chiang
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
srinivasrao marri
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic