• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDiscuss Test5 Question

 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following are valid code fragments:

Options

Select 1 correct option.

1. new Object[]{ "aaa", new Object(), new Vector(), 10};
2. new Object[]{ "aaa", new Object(), new Vector(), {} };
3. new Object[]{ "aaa", new Object(), new Vector(), new String[]{""} };
4. new Object[1]{ new Object() };
5. None of these is valid.


I found this question in JDiscuss Test5.

The answer given is option3. But thats giving an compiler error saying Vector class not allowed.
I think the correct answer is option 5.


Please give your suggestions.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can compile the class without any problem.



Nick
 
alchemist here
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we import the util package that works . how can a string literal "abc" be considered as an object
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can a string literal "abc" be considered as an object

A string literal itself is an object, even you dont use new String("abc").

Nick
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic