• 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

From MindQ's exam

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These are questions from MindQ's test.
1.

Which of the following are legal method declarations to add to the class Sub? Assume that each method is the only one being added.
a) public static void main( String args[] ){}
b) float methodTwo(){}
c) long methodOne( int c, long d ){}
d) int methodOne( int c, long d ) throws ArithmeticException{}
e) int methodOne( int c, long d ) throws FileNotFoundException{}
The answer given are a,b and e.I think choice d is also correct,there is no restriction to throw unchecked exception
when overriding in subclasses.

2.How many objects are eligible for garbage collection once execution has reached the line labeled Line A?
String name;
String newName = "Nick";
newName = "Jason";
name = "Frieda";
String newestName = name;
name = null;
//Line A
a) 0
b) 1
c) 2
d) 3
e) 4
The answer given is b.According to me the answer is a,because the ref name is assigned to anther object which is
referenced by ref newestName. So in order to make the object eligible for GC newestName also has to set to null.

3. What method(s) from the java.lang.Math class might method() be if the statement
method( -4.4 ) == -4;
is true.
a) round()
b) min()
c) trunc()
d) abs()
e) floor()
f) ceil()
The answers given are a and f.I don't agree with f,since ceil() returns only double and not int.(-4 is not equal to -4.0)

Correct me if i'm wrong!!

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
on question 1 you are correct. it must be a mistake on the test.
question 2 the String "Nick" is eligible.
question 3 they are equal. it is good you know it returns double though.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THe answer D is wrong bcos in case of overriding u can either not throw a exception at all or throw a exception which is a subclass of exception thrown in overridden method, in this case since Arithmetic exception is not a subclass of IOException , so that is not valid
Correct me if i am wrong...
With regards,
sunil.s
------------------
"Winners don't do different things
They do things differently"
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For Q.1, all option except first one does not return anything inside the body (see the return type), then how's they will be ok ?. I mean their body does not contain any statement...
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jini is correct. Question 1 is wrong in a few ways. I can see what the auhor is trying to do, but technically, the correct answer is 1 becuase you are saying the other methods return long or int or float but you don't have the return statement, so you will get a compile time error.
Now let's assume they did have the return statement, then the answer would be a,b,d,e. D would be correct, because while sunilkumar is almost correct in what you are saying, this only applies to CHECKED exceptions and ArithmethicException is not a checked exception but a runtime exception. Overriding methods can throw any runtime exception they want to regardless of the overridden method.
Bill

[This message has been edited by bill bozeman (edited December 21, 2000).]
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any one tell me as why 'C' is not added with the list of valid method in Question 1.
Thanks
 
Srinivasan Krishnan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My next doubt is that the String which is created as specified above (in the question) will be created in the String Pool (I guess String Pool is a Stack) Will an element in Stringpool be considered for GC by JVM ?
Please clarify.
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Srinivasan,
C is not correct in question 1 becuase you changed the return type and when you override a method, the signature must be the same.
As for the String, you are correct in your thinking, or from at least what I have heard, but you still get questions like this in mocks. I think you still get them in mocks because it is easier to use Strings than to create other objects becuase everyone is comfortable with Strings and they are easy to see. But Strings are treated differently so they shouldn't be used. On questions like this, I would assume they are new objects and answer like that on the mocks, but Sun will either create the strings with new or use different objects, that my guess at least.
Bill
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic