Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Java maybe, some help with something puzzling

Thread view: 
Poindexter - 11 Oct 2006 02:51 GMT
Hi all,
     I was given this quiz as it were.  I'm asked certain questions about
two snippets of code.  The questions do not indicate the programming
language.  I'm mainly familiar with java methods but don't know if other
languages would also use "methods."  I'm also a bit confused because an
Array, which is indicated in the code below, should have the square brackets
[] and yet this code snippet is lacking that.  Any advice on what I might
want to look at to understand this code further would be
greatly appreciated.  Sorry if I seem ignorant here.
1. Consider the following method:

private int wrongCode(Integer num){
if (num > 6){
return num - 5;
} else {
return num.parseInt();
}
}
What are the errors?

2. Consider the following methods:

public int run() {
List group1 = new ArrayList();
for (int i=0;i<3;i++) {
   group1.add(i);
}
List group2 = this.makeNewList(group1);
     return group2.size() - group1.size();
}
private List makeNewList(List list) {
List other = list;
other.remove(other.size() - 1);
return other;
}
What value is returned from the method run() after it is called?

Thanks,
bruce
Andrew Thompson - 11 Oct 2006 03:00 GMT
> Hi all,
>       I was given this quiz as it were.  ..

Give it back.

(Follow-ups set to comp.lang.java.programmer only)

Andrew T.
Mark Jeffcoat - 11 Oct 2006 10:08 GMT
> Hi all,
>       I was given this quiz as it were.  I'm asked certain questions about
[quoted text clipped - 5 lines]
> want to look at to understand this code further would be
> greatly appreciated.  Sorry if I seem ignorant here.

Homework? Job interview?  I'll give a few hints:

First, it's definitely Java.

> 1. Consider the following method:
>
[quoted text clipped - 6 lines]
> }
> What are the errors?

Have you tried putting this method into
a class and compiling? The compiler will
tell you quite directly what's wrong.

> 2. Consider the following methods:
>
[quoted text clipped - 12 lines]
> }
> What value is returned from the method run() after it is called?

ArrayList is a List, not an array (thus, no []).
It's backed by an array, which may give you some hints
about how it should perform. See the javadocs.

If you just want to know the value, you can just
ask Java. No problem. Really, though, this question
is asking you to think about the difference between
a reference, and the Object the reference points to.

Signature

Mark Jeffcoat
Austin, TX



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.