1)Which of the following are true about garbage collection?
a] we can set the object references to null to ensure that garbage collection will run perfectly.
True as this will speed-up the "gc" process as the JVM will realise that since the refernces are set to "null" it can treat the object eligible for gc.
b] Local variables are candidate for garbage collection when the method returns (finished).
False not neccessarily in case the locally created variables may return the refernce back to the callee method so in such a situation this variables object will not be gc'ed.
c] To use finalize() you must use a try-catch block or rethrow the error object.
True, finalize() method throws a checked exception (of Throwable type) so it must be caught or declared to be thrown in the callee method.
d] The JVM will never run out of memory
False, ofcourse it can run-out of memory, JVM does not
gurantee that it has perpetual supply of memory.
e] Garbage collection mechanism cannot be forced
True , as even by a call to System.gc() it is not
neccessary that JVM will definitely run the garbage collection mechanism.
10. Which of the following are true?
a] Any class that includes a finalize method is not necessary to invoke super class�s finalize() method.
False Please note that finalize() method is a protected method of Object. So when you are overriding it , you must call the super's (i.e, Object class) finalize otherwise you can land up in serious memory issues.
b] Java uses mark sweep garbage collection algorithm
True
c] It is guaranteed that only objects with no references will be garbage collected.
True, JVM does this check before gc'ing an object.
d] you can suggest when garbage collection will happen
False, you can not predict when the garbage collection will happen , you can only speed-up or make object's eligible for garbage collection
Q Which of the following main method in java application is correct?
a] public static main(String args[])
False, return type is "missing".
b] static public void main(String []a)
True, order of static and public doesnt matter.
c] private static void main(String args[])
False, ofcourse the code runs . THIS a
BUG in the JVM.
d] public void static main(String args[])
False, return type can't be "static".
e] public static void main(String)
False, no "args[]" so invalid.
f] static void main(String args[])
True, public access modifier is missing in favour of default access modifier. From SCJP point of view, this is wrong.
hi ravindra ,
you say that public static void main(String ) method sinot valid
but we can have overloaded method those were the forms of stndard main() . now what to do whenthis type of ques comes in exam what is the answer to the above question
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|