Question: 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).
oop java
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
