48. Consider the following class definition. public class Rectangle private double length; private double width; public Rectangle () length = 0; width = 0 public Rectangle (double l, double w) length = l; width = w; public void set (double l, double w) length = 1; width = W; public void print () System.out.println(length + "+width); public double area () return length width; public double perimeter () return 2 * length + 2 * width; } Which of the following statements correctly instantiates the Rectangle object myRectangle? (1) myRectangle (ii) Rectangle myRectangle = new Rectangle (12.5, 6); (iii) class Rectangle myRectangle = new Rectangle (12.5, 6); = new Rectangle (12.5, 6); a. Only (i) b. Only (ii) c. Only (iii) d. Both (ii) and (iii)
48. Consider the following class definition. public class Rectangle private double length; private double width; public Rectangle () length = 0; width = 0 public Rectangle (double l, double w) length = l; width = w; public void set (double l, double w) length = 1; width = W; public void print () System.out.println(length + "+width); public double area () return length width; public double perimeter () return 2 * length + 2 * width; } Which of the following statements correctly instantiates the Rectangle object myRectangle? (1) myRectangle (ii) Rectangle myRectangle = new Rectangle (12.5, 6); (iii) class Rectangle myRectangle = new Rectangle (12.5, 6); = new Rectangle (12.5, 6); a. Only (i) b. Only (ii) c. Only (iii) d. Both (ii) and (iii)
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question

Transcribed Image Text:```plaintext
49. Consider the following class definition.
public class Cylinder
{
private double baseRadius;
private double height;
public Cylinder()
{
baseRadius = 0;
height = 0;
}
public Cylinder(double l, double h)
{
baseRadius = l;
height = h;
}
public void set(double r, double h)
{
baseRadius = r;
height = h;
}
public String toString()
{
return (baseRadius + " " + height);
}
public double SurfaceArea()
{
return 2 * 3.14 * baseRadius * height;
}
public double volume()
{
return 3.14 * baseRadius * baseRadius * height;
}
}
Which of the following statements correctly instantiates the Cylinder object myCylinder?
(i) Cylinder myCylinder = new Cylinder(2.5, 7.3);
(ii) class Cylinder myCylinder = new Cylinder(2.5, 7.3);
(iii) myCylinder = new Cylinder(2.5, 7.3);
a. Only (i)
b. Only (ii)
c. Only (iii)
d. Both (ii) and (iii)
```

Transcribed Image Text:### Consider the following class definition:
```java
public class Rectangle
{
private double length;
private double width;
public Rectangle()
{
length = 0;
width = 0;
}
public Rectangle(double l, double w)
{
length = l;
width = w;
}
public void set(double l, double w)
{
length = l;
width = w;
}
public void print()
{
System.out.println(length + " " + width);
}
public double area()
{
return length * width;
}
public double perimeter()
{
return 2 * length + 2 * width;
}
}
```
### Which of the following statements correctly instantiates the `Rectangle` object `myRectangle`?
1. `myRectangle = new Rectangle(12.5, 6);`
2. `Rectangle myRectangle = new Rectangle(12.5, 6);`
3. `class Rectangle myRectangle = new Rectangle(12.5, 6);`
#### Options:
a. Only (i)
b. Only (ii)
c. Only (iii)
d. Both (ii) and (iii)
**Explanation:**
- Statement (i) is missing the type declaration for `myRectangle`.
- In statement (ii), `myRectangle` is correctly declared and instantiated.
- In statement (iii), the use of `class` is incorrect in this context.
### Correct Answer:
b. Only (ii)
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 6 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education