• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

doubt in marcus green mock

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You want to create an instance of the java.util.Vector class that will only accept elements of type String. Which of the following lines of code will compile without error?

1 java.util.Vector <String > v = new java.util.Vector<String>();
2 java.util.Vector v <String> = new java.util.Vector();
3 java.util.Vector v = new <String> java.util.Vector();
4 java.util.Vector <String> v = new java.util.Vector()<String>;



answer is 1 , why not 1 and 2 ?

since this code produce compiler error


[ April 24, 2007: Message edited by: Eisa Ayed ]
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
See Option 2 carefully
java.util.Vector v <String> = new java.util.Vector();
 
Arad Chear
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
uh , thanks
srivisan
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eisa,
Modified code,



Why not option 2, Srini has given you the answer.




Regards,
cmbhatt
----------------------------------------

[We should take care of warnings too Java 5.0]
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic