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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:01:07+00:00 2026-06-08T04:01:07+00:00

I have a program that needs a class file written to make it run

  • 0

I have a program that needs a class file written to make it run and I cannot change the original program (a java file).

The java file that i cannot change instantiates a few versions of the class lets say something like this:

CrazyClass crazy1 = new CrazyClass();
CrazyClass crazy2 = new CrazyClass();
CrazyClass crazy3 = new CrazyClass();
//more code follows

It then sets variables in those newly instantiated classes something like this:

crazy1.var1 = 6;
crazy2.var1 = 7;
crazy3.var1 = 8;
//more code follows

Later the program actually calls those instantiated classes in a println statement like this:

System.out.println(crazy1);

and expects a message to pop out..

My question is how do I make this happen? Am I completely off base to think that classes that must be instantiated cannot have return values? I can only think that I need a method inside the class that returns the message and is automatically called, something like main but not static. Am I heading in the right direction here or totally off base? Please advise I have been reading all day and I fear I cannot see the forest for the trees at this point. Im sure its something simple.

Thank you in advance.

  • 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-08T04:01:08+00:00Added an answer on June 8, 2026 at 4:01 am

    You’ll want to override Object.toString().

    In the above print-statement, the println()-method internally calls the toString()-method on the given object. This method can be overwritten to return something meaningful. E.g:

    @Override
    public String toString(){
      return "My var1-field has a value of: "+this.var1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Flash program that needs to make url requests to send data
I have written a program in Java to read in a text file of
I have a Java program that needs to call the same external executable 6
I have a file with saved data that sometimes needs to be accessed, written
I have a program that needs to... In Activity A , do some jobs
I have a program that needs several third-party libraries, and at the moment it
I have a program that needs a lot of memory and want to set
In an embedded program I have a screen object that needs to manage a
I have a program that I need to be able to search a file
I have a legacy program that I need to run with the extension of

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.