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

The Archive Base Latest Questions

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

I hope you will help me understand this Copy Constructor I took more then

  • 0

I hope you will help me understand this Copy Constructor I took more then 2 hours reading reading on websites and I didn’t understand anything about it.

I know that a copy constructor is used to copy an object of a class. But I don’t understand the code of the copy consturctor.

For Example:

public class Rectangle 
{
    private double length = 10.0;
    private double width = 10.0;


    public Rectangle(double length, double width){
        this.length = length;
        this.width = width;

    }
   //this is the copy constructor  what exactly the argument here? is it the object ref it self? please explain what happening here. and the use

    public Rectangle(Rectangle ref){
        this.length = ref.length;
        this.width = ref.width;
    }

this is what I see all the time. but I don’t understand the code at all!
ref is it going to be created in the main program?

let say this is the main program

public class rectangleTest{ 
public static void main(String[] args){
//is this new_ref object going to be created here?

Rectangle new_ref = new Rectangle(10.0 , 10.0);

This thing will not 100% clear to me unless if someone make a small class and main class showing me what’s happening

Thank you.

  • 1 1 Answer
  • 3 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:46:18+00:00Added an answer on May 23, 2026 at 4:46 am

    ref isn’t the name of a class; it’s the name of the parameter to the second constructor. So the main method would actually look like this:

    Rectangle foo = new Rectangle(10.0 , 10.0);
    
    // Create another Rectangle with the same width and height
    Rectangle bar = new Rectangle(foo);
    

    Note that objects don’t have names – variables do. Here the value of the foo variable becomes the value of the ref parameter in the second constructor, when that constructor is invoked in the last line above. Also note that the values of foo, bar and ref aren’t objects… they’re references to objects.

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

Sidebar

Related Questions

I hope I will find a help here. I have a quite complex MVC
hope this will be a quick easy question, I've just tried my app on
I hope everyone will pardon the length, and narrative fashion, of this question. I
I hope this question will not be rejected as there is no code. But
I hope this is the right place to post this and somebody can help.
Hope you guys can help me out once more before I go nuts. Iv'e
I'm starting to develop a web application in PHP that I hope will become
since my title is buzzword compliant I hope I will get lots of answers
I have now 1gb ram at work(i hope that will change soon) and jboss
I have little bit longer question for you - but hope answer will be

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.