Signup as a Tutor

As a tutor you can connect with more than a million students and grow your network.

IT Courses/Java

class HappyGarbage01 { public static void main(String args[]) { HappyGarbage01 h = new HappyGarbage01(); h.methodA(); /* Line 6 */ } Object methodA() { Object obj1 = new Object(); Object [] obj2 = new Object[1]; obj2[0] = obj1; obj1 = null; return obj2[0]; } } Where will be the most chance of the garbage collector being invoked? A. After line 9 B. After line 10 C. After line 11 D. Garbage collector never invoked in methodA()

Asked by Last Modified  

Answer
Follow 0

Please enter your answer

14 Answers   3 Likes | 0 DisLikes

After line 9

Comments
Dislike Bookmark

Java Techonologies

It takes place after line 6, but there is no possibility to check when garbage collector is called/invoked since it JVM dependent.

Comments
Dislike Bookmark

Hello Shrikant who told you that you can explicity call garbage collector. You cann't call gc explicity even when you use System.gc() it is not guranteed that gc will be invoked it is all up to JVM when an object is eligible for garbage collection.even when you use finalise method that is a protected method of java.lang.Object class

Comments
Dislike Bookmark

Join Urbanpro.com, India’s most trusted education portal for your learning requirements

POST YOUR REQUIREMENT NOW

D. Garbage collector never invoked in methodA()

Comments
Dislike Bookmark

After line 11 (because memory location allocated to obj1 will be freed as part of line 12 . so obj1 is eligible for garbage collection)

Comments
Dislike Bookmark

Java/J2EE, B.E./B.Tech/MCA SubjectsTraining

D

Comments
Dislike Bookmark

D

Comments
Dislike Bookmark

Software Engineer - java

Answer is C ... because object 1 is referred to null. So it will be eleigible for GC.

Comments
Dislike Bookmark

JAVA,JDBC,SERVLETS,JSP,STRUTS,SPRNG,HIBERNATE

After line 11

Comments
Dislike Bookmark

What Mukesh and Amit have written is absolutely correct, in this example, no scenario for GC is created as the Object created first, never lost it's reference.

Comments
Dislike Bookmark
Related Questions

IT Courses/Java

Why we are using this keyword in Java?

Asked by Kiran Bulkquestions 11 Jul

Answer 7
Follow 5
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

What is the purpose of using throws keyword in java?

Asked by Saritha Bulkquestions 11 Jul

Answer 10
Follow 7
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

Is synchronized keyword necessary, in Java, if everything that is modified in a function is local to that function?

Asked by Abishiek Bulkquestions 11 Jul

Answer 5
Follow 1
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

What programming languages should a freshman learn if he already knows C, C++, Java and Python?

Asked by Sushmita Bulkquestions 11 Jul

Answer 7
Follow 4
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

What is the use of the "this" keyword in Java?

Asked by Deepak Bulkquestions 11 Jul

Answer 9
Follow 6
Answer submitted successfully. ×

Please enter your answer

Looking for a Tutor?

Find best Tutors in your locality on UrbanPro.

FIND NOW

Now ask questions in any of the 1500+ Categories, and Get Answers from Tutors on UrbanPro.com

ASK A QUESTION

Related Lessons

Features Of Java

There is given many features of Java. They are also known as java buzzwords. The Java Features given below are simple and easy to understand. Simple. Object-Oriented. Portable. Platform independent. Secured. Robust. Architecture neutral. Dynamic. Interpreted. High...

JAVA Version History

Java Version History: There are many java versions that has been released. Current stable release of Java is Java SE 8. JDK Alpha and Beta (1995). JDK 1.0 (23rd Jan, 1996). JDK 1.1 (19th Feb, 1997). J2SE 1.2 (8th Dec, 1998). J2SE 1.3 (8th May, 2000). J2SE...

History Of Java

Java history is interesting to know. The history of java starts from Green Team. Java team members (also known as Green Team), initiated a revolutionary task to develop a language for digital devices such as set-top boxes, televisions etc. For the green...

10 Cool SQL Optimizations That Do Not Depend On The Cost Model

Today, we don’t want to talk about cost based optimisation, i.e. optimisations that depend on a database’s cost model. We’ll look into much simpler optimisations that can be implemented purely based on meta data (e.g. constraints) and...

jOOQ 3.10 Supports JPA Attribute Converter

One of the cooler hidden features in jOOQ is the JPADatabase, which allows for reverse engineering a pre-existing set of JPA-annotated entities to generate jOOQ code. For instance, you could write these entities here: @Entity public class Actor { ...

Sponsored

Find Best Java Training Classes?

Find Now »