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

  • Home
  • SEARCH
  • 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 6200023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:17:34+00:00 2026-05-24T04:17:34+00:00

Please help me understand this code. I am new to java. // C.java class

  • 0

Please help me understand this code. I am new to java.

// C.java
class C { 
  public static void main(String arg[]) { 
    System.out.println("A"+new C()); 
  } 
  public String toString() { 
    System.out.print("B"); 
    return "C"; 
  } 
}
// output:
// BAC  
  • 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-05-24T04:17:35+00:00Added an answer on May 24, 2026 at 4:17 am

    You need understand 2 concepts here: Java left-to-right evaluation rule and side effect.

    "A"+new C()
    

    following the same rule. It gets “A” first, which is a String literal, put it somewhere. Then it evaluate

    new C() 
    

    it construct a C Object first, then invoke toString() method of C Object, and gets the value of C object, which is “C“, then concatenates “A” and “C” together, and println “AC“.

    Inside the toString() method of C Object, there is a System.out.print("B");
    which is invoked when Java evaluate the above expression. It is printed out before the evaluation completed.
    That is why “B” is printed first

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

Sidebar

Related Questions

Please have a look at following code : import java.util.ArrayList; import java.util.List; class Main{
Please, help me understand, what's wrong with this code. (I am trying to build
Please help me to understand below code. This is the script for drag and
I cannot understand how this is possible. Please help!! I have an app with
Could someone please help me to understand why the following block of code keeps
I am new to MVC and dependency injection. Please help me to understand how
Please help me to refactore this Javascript code. There is big form for scheduled
Please help me understand how the process goes. I understand that web browsers contain
Please help me convert this line to C#. objManagementBaseObject.SetPropertyValue(hDefKey, CType(&H & Hex(RegistryHive.LocalMachine), Long)) Related
How can I get the username/login name in Java? This is the code I

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.