Can an object be garbage collected while it is still
reachable?
Answers were Sorted based on User's Feedback
Answer / ravikiran(aptech mumbai)
yes...all the garbage ollection things depends on the
garbage collector of JVM
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / sudheer
Garbage collector is a low priority thread. We cant order to delete an object. When the object has no references and object which are out of scope will be deleted by the garbage collector to free the memory. So when an object is reachable it cant be garbage collected.
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / janet
Once an object is garbage collected, it ceases to exist. It
can no longer become reachable again.
| Is This Answer Correct ? | 0 Yes | 3 No |
Under what conditions is an object’s finalize() method invoked by the garbage collector?
What is 'finally' method in Exceptions?
What is equlas() and hashcode() contract in java? Where does it used?
How does synchronized modifier work?
What are the advantages of java over cpp?
what is the difference between String s="hello"; and String s=new String("hello");?
posted in online test
Is there any limitation of using inheritance?
Can we define private and protected modifiers for the members in interfaces?
What is difference between length and length() method in java ?
What is sleep method?
Given: 10. interface A { void x(); } 11. class B implements A { public void x() { } public voidy() { } } 12. class C extends B { public void x() {} } And: 20. java.util.List list = new java.util.ArrayList(); 21. list.add(new B()); 22. list.add(new C()); 23. for (A a:list) { 24. a.x(); 25. a.y();; 26. } What is the result? 1 Compilation fails because of an error in line 25. 2 The code runs with no output. 3 An exception is thrown at runtime. 4 Compilation fails because of an error in line 20.