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 8
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 5
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

Comparable vs Comparator

java.lang.Comparable java.util.Comparator For comparing some other object with its own object. Ex. I am comparing myself to some other employee. Method signature is: int compareTo (T object). For implementing Comparable, access to the original class...

ClassNotFoundException vs NoClassDefFoundError

ClassNotFoundException NoClassDefFoundError It is an exception and happens due to programmer’s mistake and can be recovered by updating the code. Thrown when an application tries to load a class through its String name using Class.forName or...

Java: A Quick Overview

Not purely Object Oriented: It doesn't support multiple inheritence, it supports primitive data types and static members. Doesn’t support multiple inheritance: Reason is diamond problem i.e., if both parent classes have same method & not overridden...

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...

Sponsored

Find Best Java Training Classes?

Find Now »