Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 04-15-2006, 10:38 AM   #1
Member (11 bit)
 
inflames988's Avatar
 
Join Date: Aug 2003
Location: Silicon Valley
Posts: 1,512
couple questions about java!

hey guys, im still alive! havent been around in a while....busy with schoolwork, approaching exams, college search, etc etc etc....but as i prepare for my AP Computer Science A (Java) exam i had a few questions on a practice exam we have...

1.)

private static void recur(int n)
{
if (n != 0)
{
recur(n-2);
System.out.print(n+ " ");
}
}

Question: what is printed as the result of recur(7)?
im stuck between two options, that either alot of numbers are printed, or no numbers are printed. i coded it on my comp and i cant see numbers because it fills up with error messages so fast, but it wont let me to scroll up to see if any numbers were printed at the start.

2.) What is 100(hex)-10(hex)...i had no idea on this one, was between 256(dec) and 240(dec) but wasnt sure....definetely wasnt part of the AP curriculum as ive read 3 books on it!

3.) this is one of these weird casting questions based on the marine biology case simulation, but they can really do it with any class and its daugher class...basically its something like this:

(superclass) s = new (daughterclass);
for example: Fish s = new AgingFish; \\ where AgingFish extends Fish

then they ask which of the following is "legal"

I. s.age(); \\ where age is a method of the daughter class aging fish
II. ((AgingFish)s).age(); \\ same as I but s is casted to an AgingFish
III. s.location(); \\ location is a method of fish

i know for sure III works, i think its II and III, options are:
I only
II only
III only
I and II
II and III
inflames988 is offline   Reply With Quote
Old 04-15-2006, 03:03 PM   #2
Member (13 bit)
 
Floppyman's Avatar
 
Join Date: Mar 1999
Posts: 6,791
1) With n=7, and you calling the function recursively with n-2 as the argument, it is never going to be 0, so essentially you'll have infinite recursion and no numbers will be printed.

2) Hex is just base 16. So 100(hex) = 0*16^0+0*16^1+1*16^2 and 10(hex) = 0*16^0+1*16^1 I'll let you doublecheck the math on that but I believe the answer is 256-16 = 240

3) I'm not 100 percent sure on that one, but I believe 2 and 3 are correct. Since agingfish extends fish, I don't think you are allowed to call an agingfish method on fish. However, as you know, it works the other way around, i.e. you can call a fish method on agingfish since agingfish extends fish.

Hope this helps.
Floppyman is offline   Reply With Quote
Old 04-15-2006, 03:52 PM   #3
Member (11 bit)
 
inflames988's Avatar
 
Join Date: Aug 2003
Location: Silicon Valley
Posts: 1,512
Quote:
Originally Posted by Floppyman
1) With n=7, and you calling the function recursively with n-2 as the argument, it is never going to be 0, so essentially you'll have infinite recursion and no numbers will be printed.

2) Hex is just base 16. So 100(hex) = 0*16^0+0*16^1+1*16^2 and 10(hex) = 0*16^0+1*16^1 I'll let you doublecheck the math on that but I believe the answer is 256-16 = 240

3) I'm not 100 percent sure on that one, but I believe 2 and 3 are correct. Since agingfish extends fish, I don't think you are allowed to call an agingfish method on fish. However, as you know, it works the other way around, i.e. you can call a fish method on agingfish since agingfish extends fish.

Hope this helps.
sure does! you answered evertyhing, and confirmed what i thought for number 3...its jsut that i was disputing that answer with someone else but i really think its II and III as well. and that does make sense, since the recursion is infinite it will never actually print out the numbers....thanks! anyone taken the APCS A test? im kinda worried, but for the most part i know the stuff, and luckily the free responses are pretty general and each part can be coded in like less than 10 lines in most cases, i think ill be ok!
inflames988 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

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



All times are GMT -5. The time now is 05:08 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2