• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

3 java questions

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can somebody help with their answers
Qustion 1.
String readString() {
char buf[] = new char[80];
Reader in = new InputStreamReader(System.in);
in.read(buf, 0, 80);
return new String(buf);
}
What is wrong with method readString()?
Choice 1
you can not cast InputStreamReader into Reader
Choice 2
all IO methods must be declared public
Choice 3
logic to catch exceptions for the InputStream statements is missing
Choice 4
an InputStreamReader object can not be bound to standard input
Choice 5
String objects can not be instantiated with a character array

Question 2.
Can an applet "test" the system to determine its access rights? Why, or why not?
Choice 1
no, applets can not query the SecurityManager directly
Choice 2
yes, by attempting various operations and catching SecurityException's
Choice 3
no, the information is in the System object, which is restricted from applets
Choice 4
yes, by querying its ClassLoader object
Choice 5
no, the applet is automatically terminated when
Question 3
public int m1(int x) {
int count=1;
try {
count += x;
count += m2(count);
count++;
}
catch(ArithmeticException e) { count -= x; }
finally { count += 3; }
count++;
return count;
}
When m1(2) is invoked, m2() returns a value of 2 and m1() returns ________.
Choice 1
5
Choice 2
6
Choice 3
7
Choice 4
10
Choice 5
nothing. The system exits
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd say that the following is the answers:
1: choice #3
2: Probably #4, but not sure
3: choice #4 (1+2=3, 3+2=5, 5++=6,6+3=9,9++=10)
Anyone disagree?
/Mike
 
Chiran Mathur
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On questions 3 I am still not sure beacuse it asks for the value of m2() and not m2(x) whihc is 10 as you have pinted out. Can anyone clarify?
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
m2() is simply a shorthand way of saying the m2 method. It would only be confusing if m2 was overloaded with a method that takes no parameters.
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic