|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (11 bit)
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 |
|
|
|
|
|
#2 |
|
Member (13 bit)
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. |
|
|
|
|
|
#3 | |
|
Member (11 bit)
Join Date: Aug 2003
Location: Silicon Valley
Posts: 1,512
|
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|