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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:59:05+00:00 2026-05-28T06:59:05+00:00

I have two classes : import android.cla; public class CW { public static void

  • 0

I have two classes :

import android.cla;
public class CW {

public static void main(String [] args){
    System.out.println(new cla());
 }
}

public class Cl {
   @Override
   public String toString(){
      return "LOL";
   }
}

In the first class I’m calling the objects toString() method, which has been overriden and printing it to console. It clearly returns “LOL”;

I have two questions :

  • Is it possible to return data while instantiating like this (new cla()) without overriding the objects toString() method; and

  • What is the proper term for instantiating classes like this (new cla()), that’s without declaration like : Object l = new cla()

Thanks. Please correct me on the proper terms.

  • 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-28T06:59:05+00:00Added an answer on May 28, 2026 at 6:59 am

    1 – No it isn’t. A ‘constructor’ is a special method on the class that always returns an object instance of the class. The whole point of the constructor is to return the object. So no, it can’t return anything else.

    1a – The reason that System.out.println calls the toString method is because you are asking it to print out that object to the screen, and the toString method is the method chosen by the authors of println (and the Java language in general) to give a string representation of the object.

    2 – That way of writing isn’t really called anything. It’s just an expression that you’re passing as an ‘actual parameter’ to the println method. True, it’s an expression that instantiates a new object, but it’s no different to println("a string"). You could call it an anonymous object if you really wanted to.

    2a – (old answer that doesn’t actually answer your question but I’ll keep it here) That’s just called ‘using a less derived reference† to a class’. Beware you can only call methods on the type of the reference, so if you added extra methods to your Cl class you couldn’t call them from an Object reference. Look into Liskov substitution principle.

    † ‘less derived’ or ‘supertype’ or ‘superclass’ or ‘more general class’ etc…

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

Sidebar

Related Questions

I have the following two classes: package { import flash.display.Sprite; import flash.events.Event; public class
I have the following two classes: import java.io.*; import java.util.*; public class User {
I have two classes, and want to include a static instance of one class
I have two classes, Foo and Bar, that have constructors like this: class Foo
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have two classes: Action and MyAction . The latter is declared as: class
I have two classes, Portfolio, and PortfolioImage. class PortfolioImage(models.Model): portfolio = models.ForeignKey('Portfolio', related_name='images') ...
I have two classes, Class A and Class B, both of them are subclasses
At this moment, I have two classes: UserHibernateDao and TicketHibernateDao : import java.util.List; import
Ok I have two modules, each containing a class, the problem is their classes

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.