UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

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  

14 Answers

Learn Java

Follow 0
Answer

Please enter your answer

Trainer

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...
read more
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 read less
Comments

D
Comments

Master

D. Garbage collector never invoked in methodA()
Comments

Core Java, Angular 2/4/6, J2EE, Spring Boot

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

Experience in Java and Android Trainer.

Garbage collector never invoked in methodA()
Comments

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

After line 11
Comments

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

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

D
Comments

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

IT Professional Trainer with 15 years of experience in IT Industry

D
Comments

View 12 more Answers

Related Questions

why string class is override in euals()/ hashCode Hethods?
Equals method and hash code methods compare two objects based the memory location occupied by objects. Two different objects always occupy two different locations in heap memory. So equals and hashCode...
Rami Reddy
Can we use pointer in java?
No, we can't. Java has reference variables which contains address of objects. The reference variables are substitute to pointers in java. But, we cannot perform mathematical operations on reference variables...
Manish
public class X { public static void main(String [] args) { X x = new X(); X x2 = m1(x); /* Line 6 */ X x4 = new X(); x2 = x4; /* Line 8 */ doComplexStuff(); } static X m1(X mx) { mx = new X(); return mx; } } After line 8 runs. how many objects are eligible for garbage collection?
Only one. After line 8 the original object referred to by x2 is dereferenced and ready for garbage collection. In m1(), mx ignores the object passed as argument and refers to a new object which is returned.
Srikanth
Which holds the future: Java or Python?
The future success of Java or Python depends on various factors, including industry trends, project requirements, and developer preferences. Both languages are widely used, with Java being prominent in...
Nikhil
0 0
5
What is the best book to learn data structures using Java?
There are several excellent books that can help you learn data structures using Java. 1. "Data Structures and Algorithms in Java" by Robert Lafore. 2. "Algorithms, Part I" by Robert Sedgewick and Kevin...
Shubham
0 0
5

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

What Is Applet & Its Life Cycle?
What is Applet & its life cycle?Applet is a Java programme that can be embedded into HTML page.Java Applet runs on the java enables web browsers such as Mozilla & Internet Explorer.Applets are...
I

ICreative Solution

0 0
0

Difference Of Inheritance In C++ And Java
In Java , multiple inheritance is not applicable directly but we can implement the concept by using the interfaces. In c++ and Java, the common types of inheritances are: Single Multi level Hybrid Hierarchical

How do i get best Campus / Off Campus Placement?
Companies are looking for Skilled Freshers. So build your technical skills while doing MCA / BTech / BCA / BSc (IT or CS) into below areas- 1. Strong your programming & debugging skills ...

Constructor Overloading
public class ConstructorOverloading { public ConstructorOverloading(){ System.out.println("default"); } public ConstructorOverloading(String a){ System.out.println("a"); } public ConstructorOverloading(int...
S

Sarthak C.

0 0
0

doWhile example in Java
public class doWhilePracticleEx { public void test() { } public static void main(String args) { String q1 = "Who is PM of India?"; String a1 = "Sonia Gandhi"; String a2 = "Rahul Gandhi"; String a3...
S

Sarthak C.

0 0
0

Recommended Articles

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more