Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note that every time a Shape is constructed in the Colorable Shape code, the variable totalShapes is incremented. Consider the following program class Test

image text in transcribed image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Note that every time a Shape is constructed in the "Colorable Shape code", the variable "totalShapes" is incremented. Consider the following program class Test { public static void main(String[] args) { } Shape s = new Circle ("Red", 1); Shape 32 = new Circle ("Green", 2); XXXXX; } We want to replace the "xoxx" with some code which will print out the total number of Shapes constructed. Select all of the ways(there are 2 correct ones) to print out the total number of Shapes constructed: A. System.out.println(totalShapes); OB. System.out.println(Shape.getCount()); C. System.out.println(s.totalShapes); OD. System.out.println(s.getCount()); public interface Colorable { public String getColor (); public void setColor (String c); |} 1 public abstract class Shape implements Colorable{ private static int total Shapes =0; 8 90 10 130 250 310 350 43 44 450 private String color = "Red"; private 46 47 48 49 } 50 abstract double getPerimeter(); abstract double getArea(); 180 public static int getCount() return totalShapes; public void setColor (String c) { color = c; } public String getColor() { } { } return color; public Shape(String c) { } color = c; total Shapes +=1; public double getAPRatio () { return getArea()/getPerimeter(); } public boolean equals (Object ob) { if (ob != null && getClass() == ob.getClass()) { Shapes (Shape)ob; if (color.equals (s.color)) return true; } return false; } public String toString() { } return "Shape color=" + color; 51 class Circle extends Shape 52 { 53 54 55 560 57 58 59 60 610 62 63 63 64 64 65 660 67 1 68 69 720 73 75 76 76 770 78 80 810 82 83 84 85 860 87 88 89 90 91 92 93 94 95 96 97 99} 100 private double radius; private static int totalCircles=0; public static int getCount() { return totalCircles; } public double getRadius() { } Circle(String c, double r) super (c); radius =r; totalCircles +=1; { return radius; } public double getArea() { } return Math.PI * radius* radius; public double getPerimeter() { } return 2*Math.PI* radius; } public String toString() { return super.toString() + " Circle with radius="+radius; } public boolean equals (Object ob) if (ob null && getClass() == ob.getClass()) { Circle circle = (Circle)ob; if (super.equals(ob) && radius = circle.radius) { } return true; } return false; What is true about the following line of code: Shape s = new Circle("Red", 1); O A. Only the Shape constructor will be called. B. Only the Circle constructor will be called. O C. The Circle constructor will complete, and then the Shape constructor will complete. D. The Shape constructor will complete, and then the Circle constructor will complete. Note that every time a Shape is constructed in the "Colorable Shape code", the variable "totalShapes" is incremented. Consider the following program class Test { public static void main(String[] args) { } Shape = new Circle ("Red", 1); Shape 32 = new Circle ("Green", 2); XXXXX; } We want to replace the "xox" with some code which will print out the total number of Shapes constructed. Select all of the ways(there are 2 correct ones) to print out the total number of Shapes constructed: A. System.out.println(totalShapes); OB. System.out.println(Shape.getCount()); C. System.out.println(s.totalShapes); OD. System.out.println(s.getCount()); This question is based on the Colorable_Shape code. What is true about the following line of code: Shape s = new Shape("Red"); A. The compiler will allocate a variable "s" which points to a Shape object B. This won't compile, because the Shape class is an abstract class O C. The variable "s" can be cast into a Circle class, with code like: Circle c = (Circle)s; O D.The parameter "Red" is not allowed for this Shape constructor What is output from the following code: Shape s = new Circle("Red", 1); System.out.println (s); O A. This will generate an exception, because s is an abstract class B. Shape color=Red C. Shape color=Red Circle with radius 1 D. Circle with radius 1 Shape color=Red What is true about the following code: Shape s = new Circle("Red", 1); System.out.println (s.getAPRatio()); A. This will not work as coded. However, if you cast "s" to a Circle class then it works (i.e.) System.out.println ((Circle)s.getAPRatio()); B. This will call getAPRatio in the Shape class which then tries to call getArea and getPerimeter. Because getArea and getPerimeter are abstract, the run time system calls the System default routines. OC. This will call getAPRatio in the Shape class which then tries to call getArea and getPerimeter. However, a run time error occurs, because the Shape class has no getArea or getPerimeter methods. O D. This will call getAPRatio in the Shape class which then calls getArea and getPerimeter in the Circle class. In line 1, Shape implements Colorable. This means O A. The Shape class is written with a style that is fashionable. O B. The Shape class contains all of the methods in the Interface Colorable C. The Shape class is derived (i.e. extends) from Colorable. O D. This won't compile, because the Shape class does not override the Colorable class.

Step by Step Solution

3.38 Rating (154 Votes )

There are 3 Steps involved in it

Step: 1

Lets go through each question one by one 1 What is true about the following line of code Shape s new ... 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

Java How To Program Late Objects Version

Authors: Paul Deitel, Deitel & Associates

8th Edition

0136123716, 9780136123712

More Books

Students also viewed these Programming questions

Question

What is EVA? How does it differ from ROI and residual income?

Answered: 1 week ago