Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8905367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:22:38+00:00 2026-06-15T02:22:38+00:00

I am preparing for OCPJP , and I got stuck at the following mock

  • 0

I am preparing for OCPJP, and I got stuck at the following mock exam question:

Given:

3. interface Animal { void makeNoise(); }

4. class Horse implements Animal {
5.     Long weight = 1200L;
6.     public void makeNoise() { System.out.println("whinny"); }
7. }

8. public class Icelandic extends Horse {
9.     public void makeNoise() { System.out.println("vinny"); }

10.    public static void main(String[] args) {
11.        Icelandic i1 = new Icelandic();
12.        Icelandic i2 = new Icelandic();
12.        Icelandic i3 = new Icelandic();
13.        i3 = i1; i1 = i2; i2 = null; i3 = i1;
14.    }
15. }

When line 14 is reached, how many objects are eligible for the garbage collector?

A. 0

B. 1

C. 2

D. 3

E. 4

F. 6

Their correct answer is E, i.e. four objects, but I’m not sure why. From my point of view, i2 and its weight will get eligible for garbage collection. Perhaps I’m missing something, please advise.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:22:40+00:00Added an answer on June 15, 2026 at 2:22 am

    Lets call Icelandic() on line 11 IceA, line 12 IceB, and so forth.

    After creation

    i1 = IceA
    i2 = IceB
    i3 = IceC
    

    After i3 = i1

    i1 = IceA
    i2 = IceB
    i3 = IceA
    

    After i1 = i2

    i1 = IceB
    i2 = IceB
    i3 = IceA
    

    After i2 = null

    i1 = IceB
    i2 = null
    i3 = IceA
    

    After i3 = i1

    i1 = IceB
    i2 = null
    i3 = IceB
    

    So only the Icelandic() created on line 12 remains. Now, each Icelandic() has a Long weight, so IceA and IceC are now unreferenced, meaning 4 objects (IceA, IceA.weight, IceC, IceC.weight) are available for GC.


    Other issues:

    1. args is still args, they are not counting going out of scope in this question
    2. Long weight is not declared statically, so each instance of the class has a weight object.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Preparing for exam and got stuck at this question: Allowed operators are <<,+,& no
I am preparing for an exam and I have stumbled on the following question:
In preparing to a OOP exam, I enjoyed seeing g++ compile the following code
I am currently preparing myself for the exam in Networking and I got some
I'm currently preparing a major Program-Update and ran into following problem: I've got a
I'm preparing to do an .NET exam and I came across this question. I
Im preparing for a very tricky c# exam and this question popped up while
I am preparing for Magento certification and this question really stuck me in between.
I'm preparing for my final exam for a class and am attempting to rework
I am preparing for a SCJP exam and when studying widening part it's given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.