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 8969033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:32:13+00:00 2026-06-15T17:32:13+00:00

public class Test10 { public static void main( String[] args ) { Thing2 first

  • 0
public class Test10 
{ 
  public static void main( String[] args ) 
  { 
    Thing2 first = new Thing2( 1 ); 
    Thing2 second = new Thing2( 2 ); 
    Thing2 temp = second; 
    second = first; 
    first = temp; 
    System.out.println( first.toString() ); 
    System.out.println( second.toString() ); 
    Thing2 third = new Thing2( 3 ); 
    Thing2 fourth = new Thing2( 4 ); 
    third.swap1( fourth ); 
    System.out.println( third.toString() ); 
    System.out.println( fourth.toString() ); 
    second.setCount( fourth.getCount() ); 
    third = first; 
    System.out.println( third == first ); 
    System.out.println( fourth == second ); 
    System.out.println( first.toString().equals( third.toString() ) ); 
    System.out.println( second.toString().equals( fourth.toString() ) ); 
    System.out.println( first.toString() ); 
    System.out.println( second.toString() ); 
    System.out.println( third.toString() ); 
    System.out.println( fourth.toString() ); 
    first = new Thing2( 1 ); 
    second = new Thing2( 2 ); 
    first.swap2( second ); 
    System.out.println( first.toString() ); 
    System.out.println( second.toString() ); 
  } 
} 



class Thing2 
{ 
  private int count; 

  public Thing2( int count ) 
  { 
    this.count = count; 
  } 
  public int getCount() 
  { 
    return this.count; 
  } 
  public void setCount( int count ) 
  { 
    this.count = count; 
  } 
  public String toString() 
  { 
    String s = " "; 
    switch( this.count ) 
    { 
      case 1: 
        s = s + "first ";  
      case 2: 
        s = s + "mid "; 
        break; 
      case 3: 
        s = s + "last "; 
        break; 
      default: 
        s = s + "rest "; 
        break; 
    } 
    return s; 
  } 
  public void swap1( Thing2 t2 ) 
  { 
    int temp; 
    temp = this.getCount(); 
    this.setCount( t2.getCount() ); 
    t2.setCount( temp ); 
  } 
  public void swap2( Thing2 t2 ) 
  { 
    Thing2 temp; 
    Thing2 t1 = this; 
    temp = t1; 
    t1 = t2; 
    t2 = temp; 
  } 
} 

Given the following definition of class Thing2, what is the output of
the Java application Test10?

Hey guys, this is for one of my classes. There are two classes (listed above), Thing2 and Test10. This is the output, but I don’t understand how to get to the output (i.e. what points to what and what’s the order everything gets resolved in?). Thanks!

mid
first mid
rest  
last
true
false
true
true 
mid  
last 
mid 
last
first mid
mid
  • 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-15T17:32:14+00:00Added an answer on June 15, 2026 at 5:32 pm

    One trick is that case 1 in your switch statement does not have a break statement, so the code continue to the case 2 instruction and creates the string “first mid” instead of “first” for Thing(1)

    it might help to add comments to your print statements like this

    System.out.println("First is " + first.toString());
    System.out.println("third == first?" + (first == third));
    

    One you do that, add more print statements.

    Think of each variable as a big arrow.

    The statement a = new Thing(2) makes a Thing with the word “mid” and points the a arrow at it.

    The statement a = b take whatever the b arrow was looking at and points the a arrow at the same thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Test1{ public static void main(String[] args){ StringBuffer s=new StringBuffer(abcde); reverseString(s); System.out.println(s); }
package com.test01; public class test01 { public static void main(String[] args) { System.out.println(hi); }
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public class A { public void foo() { System.out.println(A's foo); } } public class
public class A { private A(int param1, String param2) {} public static A createFromCursor(Cursor
This is my first Class Hello.java public class Hello { String name = ;
I have a Java program with code: public class Test1 { public static void
I saw the following program on the internet public class Test1{ public static void
public interface ITest { void Somethink(); } public class Test1 : ITest { public
I wrote two methods to check there performance public class Test1 { private String

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.