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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:18:57+00:00 2026-05-24T07:18:57+00:00

I need to know the order, in which the constructors will be called. Point

  • 0

I need to know the order, in which the constructors will be called.

Point class:

public class Point
{
    public int x = 0;
    public int y = 0;

    // a constructor!
    public Point(int a, int b) {
        x = a;
        y = b;
    }
} 

Rectangle class:

public class Rectangle
{
    public int width = 0;
    public int height = 0;
    public Point origin;

    // four constructors
    public Rectangle() {
        origin = new Point(0, 0);
    }
    public Rectangle(Point p) {
        origin = p;
    }
    public Rectangle(int w, int h) {
        origin = new Point(0, 0);
        width = w;
        height = h;
    }
    public Rectangle(Point p, int w, int h) {
       origin = p;
       width = w;
       height = h;
    }

    // a method for moving the rectangle
    public void move(int x, int y) {
        origin.x = x;
        origin.y = y;
    }

    // a method for computing the area of the rectangle
    public int getArea() {
        return width * height;
    }
}

A class which creates objects:

public class CreateObjectDemo {
    public static void main(String[] args) {

        //Declare and create a point object
        //and two rectangle objects.
        Point originOne = new Point(23, 94);
        Rectangle rectOne = new Rectangle(originOne, 100, 200);
        Rectangle rectTwo = new Rectangle(50, 100);
        System.out.println("Width of rectOne: " +  rectOne.width);
        System.out.println("Height of rectOne: " + rectOne.height);
        System.out.println("Area of rectOne: " + rectOne.getArea());

        rectTwo.origin = originOne;
    }
}
  1. In which order are the constructors in class Rectangle called?

  2. When will the public Rectangle(Point p) be called?

  3. What does the statement rectTwo.origin = originOne do ?

The program is from Oracle’s Java Tutorial site.

  • 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-24T07:18:59+00:00Added an answer on May 24, 2026 at 7:18 am

    In general, the control flow is in program order (i.e. left-to-right), with the following exceptions:

    • Parameters to methods and constructors are evaluated before the method/constructors itself
    • The program starts with the main method.

    Thus we have the following order:

    1. Point originOne = new Point(23, 94); – this will call the Point constructor.
    2. Rectangle rectOne = new Rectangle(originOne, 100, 200); – this will call the Rectangle constructor with a Point and two int arguments.
    3. Rectangle rectTwo = new Rectangle(50, 100); – this will call the Rectangle constructor with two int arguments.

      1. This constructor, in turn, will in origin = new Point(0, 0); call the Point constructor.

    There are no more explicit constructor calls. But each of these calls includes an implicit call to the constructor of its superclass (which is Object here) at the start.

    The constructor Rectangle(Point) is not called at all, it seems.

    rectTwo.origin = originOne; changes the origin of the second rectangle from (0,0) to the same point which is used by rectOne, e.g. (23,94).

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

Sidebar

Related Questions

In order to use normal mapping in GLSL shaders, you need to know the
I need to know when the memory will be allocated for a particular program.
I need to change the order in which my for-each is executed only if
I wanna know study what to get which certificate in Java .. I need
I need to be able to determine the order which rows have been inserted
I need to know this differences in order to undestand how to use them
Need to know this so that i could send DTMF and that is going
I need to know about Epoll On linux System. Could you recommend manual or
I need to know how the performance of different XML tools (parsers, validators, XPath
I need to know how much space occupies all the databases inside an SQL

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.