Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given: class Rectangle { private int x,y; private int width, height; public Rectangle() { this (0,0,1,1); //statement X } public Rectangle(int width, int height) {

Given:

class Rectangle

{

private int x,y;

private int width, height;

public Rectangle()

{

this (0,0,1,1); //statement X

}

public Rectangle(int width, int height)

{

this (0,0,width,height); //statement Y

}

public Rectangle(int x, int y, int width, int height)

{

this.x= x;

this.y=y;

this.width= width;

this.height= height;

}

public double getArea()

{

return height * width;

}

public double getPerimeter()

{

return 2 * (height + width);

}

}

class RectangleDemo

{

public static void main(String[] args)

{

Rectangle rectangle1 = new Rectangle(3,3);// statement Z

System.out.println("Area of Rectangle is "

+ rectangle1.getArea());

System.out.println("Perimeter of Rectangle is "

+ rectangle1.getPerimeter());

}

}

(a) What is constructor overloading? (b) What is the usage of this keyword in statement (X) and (Y)?

(c) Write all possible statements of (Z).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

Define and operationalize types of employment discrimination.

Answered: 1 week ago

Question

LO3 Outline strategic compensation decisions.

Answered: 1 week ago