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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:52:10+00:00 2026-05-18T11:52:10+00:00

I have a 3 questions on overloaded constructors: 1.On the line marked line 1,

  • 0

I have a 3 questions on overloaded constructors:

1.On the line marked line 1,
I am calling an overloaded constructor but the compiler doesn’t resolve the call,
is there something else I need to do?

  1. On the line marked with a 2,
    The compiler complains that the “this()” needs to be the first statement in the
    method, when it is. What’s with that?

  2. If I am writing an overloaded constructor, and I haven’t overridden the default constructor do I need an explicit “this();” in the overloaded constructor, if i want to execute the behavior of the default constructor, or is it included in all constructors for “free”?

.

class JavaSnippet {


public static void main(String[] args) {

          String MenuItemName="Coffee";
          double MenuItemPrice=1.0;
          Item MenuItem;
     //1-> MenuItem=new Item(MenuItemName,MenuItemPrice);// Get "cannot find symbol"
    }
}         

 class Item {
    String name;
     double price;

      public void  Item(String InName, double InPrice)   {
// 2-> this();// get "call to this must be first statement in constructor"


     name=InName;
     price=InPrice;
     }

}
  • 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-18T11:52:11+00:00Added an answer on May 18, 2026 at 11:52 am

    Your Constructor has a method signature.
    The constructor of item should be

    public Item(String InName, double InPrice) { ... } 
    

    and not

    public void Item(...)
    

    And your second question:
    If you want to call the other (not overriden, but explicitely defined parameterless) constructor, you need an explicit call to this(). If you want to call a constructor from a super-class, the call is super().

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

Sidebar

Related Questions

I am going to be making a small user system but I have questions.
similar questions have been asked before but I cant find an exact match to
Similar questions have been asked but cannot find a solution that works well. What
Yet another in my series of questions regarding constructors in Delphi. i have a
I have questions about System.Threading.ThreadStart Class : where can I find its specifications (
I want to create some simple navigation in sencha touch 2. I have questions
have 2 questions : A computer with 32-bit address uses 2-level page table (9
I have 2 questions on kendo combobox change event. On change event I want
I have some questions concering routing with Codeigniter. What I´m doing now is the
I have some questions regarding the following css that I found: html, body {

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.