Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-30-2007, 09:41 AM
Member
 
Join Date: Jul 2007
Posts: 11
money123 is on a distinguished road
Which statement is throwing a runtime error....
import java.util.*;
public void printStrings (List stringList) {
if (stringList != null) {
Iterator li = stringList.iterator();
while (li.hasNext()) {
System.out.println( (String) li.next());
}
}
}

Which one of the following statements highlights the assumed risk of potential run-time error in the above code?

Choice 1
System.out may have been redirected to a file rather than the terminal.

Choice 2
You do not know that stringList contains only String objects, so the cast could fail.

Choice 3
You need to check the size of the List using its size() method before accessing it so you do not read past the end of the list.

Choice 4
Since printStrings returns "void," you have no way to return a failure code.

Choice 5
The object referenced by stringList may or may not implement the iterator() method.

I have got no idea on this question.... so tx for an explaination of answer in advance........
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-30-2007, 02:55 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Choice 1
I don't think this would be a problem.

Choice 2
True statement.

Choice 3
Negative. Iterator takes care of this.

Choice 4
No failure code needed; we're just printing to console.

Choice 5
Unlikely. You are importing the java.util package so we'll assume that this is a java.util.List which has an iterator method/implements iterable. Of course you could have another, local (lame) List class in your classpath which does not have an iterator method.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Main method throwing specific Exception bugger New To Java 3 01-22-2008 05:08 AM
throwing Exception bugger New To Java 3 11-09-2007 11:35 PM
Help with if statement carl New To Java 1 08-06-2007 09:53 AM
Statement or Prepared Statement ? paty Database 3 08-01-2007 06:45 PM
If Statement aDrizzle New To Java 4 07-08-2007 10:55 PM


All times are GMT +3. The time now is 11:21 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org