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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:11:30+00:00 2026-05-23T04:11:30+00:00

Create a class with a default constructor (one that takes no arguments) that prints

  • 0
  • Create a class with a default constructor (one that takes no arguments) that prints a message. In your main() method, create an object of this class.
  • Add an overloaded constructor to your code from step 1. The new constructor should take a String argument and print it along with your message. Modify main() so that it creates a second object of this class, using the new constructor.

So the second part is literally like written in another language to me I have absolutely no idea how to do that, and the first part here’s what I got so far:

public class Constructors {
    System.out.println("Message");
    public static void main(String[] args) {
    }
}

It’s giving me an error when I’m just trying to print that message. I’m so confused, I’m not asking you to do my lab for me by any means but I’m so confused by this it’s out of control.

  • 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-23T04:11:31+00:00Added an answer on May 23, 2026 at 4:11 am

    The constructor shouldn’t be the name of your class, the constructor is the method that creates an instance of your class (object)

    So the first point means that you create an object without parameters that will print a message when you call it from the main method

    public class WhateverClass{
    
        //this is the first constructor
        public WhateverClass(){
    
            System.out.prinln("A message");
    
        }
    
        //this is the main method
        public static void main (String[] args){
            new WhateverClass(); //will print the message
        }
    }
    

    Then you create another constructor that gonna overload the first one because it gonna have the same signature except it gonna takes a parameter. And then you call it from main method exactly as the first one. Here:

    public class WhateverClass{
    
        //this is the first constructor
        public WhateverClass(){
    
            System.out.prinln("A message");
    
        }
    
        //this is the second constructor
        public WhateverClass(String message){
    
            System.out.prinln(message);
    
        }
    
        //this is the main method
        public static void main (String[] args){
            new WhateverClass(); //will print the message
            new WhateverClass("A message");
        }
    }
    

    And your exemple doesn’t work because your print method is not in any method and cannot be executed from where it is.

    You should really read books and articles about the basics of OO programmation.

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

Sidebar

Related Questions

I dislike the default Javadocs generated for me when I create a Class or
I need to create class Dog and PurebredDog extending Dog. Problem is that Dog
I wonder, whether it is possible to create class-methods in VBA. By class-method I
I've found a task on some Java programming competition. One must create class Sentence
I managed to create a class using CodeDom and add a single method to
I created a new Logger object like this: log4cplus::Logger m_WebAccessLogger; //a class member Then
I have always felt that in general the main work of a class should
If I define a class with a private default constructor and a public constructor
I am defining a class which has a DateTime object as one of the
I create class libraries, some which are used by others around the world, and

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.