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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:06:44+00:00 2026-06-06T09:06:44+00:00

here I am trying to call overloaded constructor after some condition has met in

  • 0

here I am trying to call overloaded constructor after some condition has met in my main() program , which is given by variable a. Code works fine when I am using only default constructor , but I need to call overloaded constructor at some point and it fails . folowing is code:

overloaded constructor :

public Paddle(int a){

   if(a ==1){
       ImageIcon ii = new ImageIcon(this.getClass().getResource(paddle1));
       image = ii.getImage();
   }
   else {
       ImageIcon ii = new ImageIcon(this.getClass().getResource(paddle2));
       image = ii.getImage();
   }
    width = image.getWidth(null);
    height = image.getHeight(null);
  resetState();
  }

//      further initialization --

default constructor :

 public Paddle(){

        ImageIcon ii = new ImageIcon(this.getClass().getResource(paddle));
        image = ii.getImage();

        width = image.getWidth(null);
        height = image.getHeight(null);
        System.out.println(height+" "+width);
        resetState();
 }

thanks for help in advance, further queries can be asked but I think this piece of code has some problem . Thank you

  • 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-06T09:06:45+00:00Added an answer on June 6, 2026 at 9:06 am

    Answer

    You are not setting the instance variable image in the overloaded constructor.

    Correct Way

    The way you are doing it is violating DRY ( Don’t Repeat Yourself )!

    The best way is to make the no arg constructor call the overloaded one and then set the instance variable image in one place.

    public Paddle(final int i) 
    { 
       if (i==1) { this.image = one thing } 
       else 
       { this.image = another thing } 
    }
    
    public Paddle() { this(0); }
    

    A better way would be to just pass in the resource to a single constructor and be done with it, without seeing all the code, this looks overly complicated.

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

Sidebar

Related Questions

i trying to call a COM-Object which is described here Is it possible to
I am trying to call a java script function from java code. Here is
I am trying to get the code found here: http://snipplr.com/view/26643/mbprogresshud-with-an-asynchronous-nsurlconnection-call/ to work in my
Here I am trying to implement the jQuery I have two main files one
I'm trying to use SFINAE to detect if a class has an overloaded member
I am trying to call a method on this time : 00:01 AM here
I'm trying to call another jQuery function if confirm is true, here's the code:
I am trying to call my excel macro using vbs. Here is a snippet
I am trying to call an external js file from another js file. Here
Here is my issue. I am trying to call a page: foo.php?docID=bar and return

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.