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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:31:50+00:00 2026-06-02T03:31:50+00:00

I am trying to understand what is the difference between the following constructors in

  • 0

I am trying to understand what is the difference between the following constructors in java in class

Box
{
    Box(Box ob)
    {
     width = ob.width;
     height = ob.height;
     depth = ob.depth;
    }

    Box(double w, double h, double d)
    {
     width = w;
     height = h;
     depth = d;
    }

    Box()
    {
     width = 0;
     height = 0;
     depth = 0;

    }

    Box(double width, double height, double depth)
    {
     this.width = width;
     this.height = height;
     this.depth = depth;
    }
}

Cheers everyone

  • 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-02T03:31:52+00:00Added an answer on June 2, 2026 at 3:31 am

    First is the copy constructor which is used to copy the values of one object to another during initialization.

    Second and Fourth is a parametrized constructor which contains all the data members of the class. But it is recomended to use the fourth and most of the IDE(all that I know) will auto generate the 4th as it is easier to read and has the same context

    Third is a default constructor. Used to set default values. See it does not take any inputs(as parameter)

    Box b = new Box();//Default constructor
    Box b1 = new Box(1.0,2.0,3.0);//Parameterized constructor completely defining the object
    Box b2 = new Box(b1);//Copy constructor will copy the values but both will have a different reference
    b2 = b1;//b2 now refers to object referenced by b1. So the earlier reference for b2 will be taken by GC(garbage Collector)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand the difference between this: if (isset($_POST['Submit'])) { //do something
I am trying to understand the difference between this list: UIRequiredDeviceCapabilities and individual keys
Been trying my best to understand this correctly. What is the difference between an
I am trying to understand this particular difference between the direct and delegated event
I'm trying to understand the difference between a squash and a rebase. As I
I'm trying to understand the difference between sequences and lists. In F# there is
I am trying to understand the difference between 2 methods that have the same
I'm really trying to understand the difference between OpenID and OAuth? Maybe they're two
I'm trying to access my class's private enum. But I don't understand the difference
I'm trying to understand the difference between regular Memcache and Doctrine's MemcacheCache. In my

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.