Note that every time a Shape is constructed in the Colorable Shape code, the variable totalShapes...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
Lets go through each question one by one 1 What is true about the following line of code Shape s new ... View the full answer
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
How do you simplify the max method in the following, using the conditional operator? 1: /** Return the max of two numbers */ 2: public static int max ( int num1, int num2 ) { 3: int result; 4: 5: if...
-
Using a resource-based view, explain why some firms improve their economic performance by adopting a CSR strategy, whereas others achieve no results or damaging results.
-
If the plan in the previous problem wants to fully fund and immunize its position, how much of its portfolio should it allocate to one-year zero-coupon bonds and perpetuities, respectively, if these...
-
What do you think is the importance of Event Marketing and Promotion? Cite an example analyze the concept of event marketing and its importance of customer engagement and brand development.
-
Which of the following is necessary for fraud to occur? a. Perceived pressure b. Perceived opportunity C. Rationalization d. All three are necessary.
-
Sunshine Baking Company is a diversified food products company with three operating divisions organized as investment centers. Condensed data taken from the records of the three divisions for the...
-
Pharoah Corp. is considering purchasing one of two new diagnostic machines. Either machine would make it possible for the company to bid on jobs that it currently isn't equipped to do. Estimates...
-
Halifax Manufacturing allows its customers to return merchandise for any reason and receive a credit to their accounts. All of Halifax's sales are for credit (no cash is collected at the time of...
-
A 55.0 N backpack full of unread books (it's probably yours) is at rest on a level tabletop. The coefficient of static friction between the bag and tabletop is 0.10 and the kinetic coefficient of...
-
Find all eigenvalues and a corresponding eigenvector for each matrix below without cal- culations by thinking it out using the linear transformation's geometric interpretation. Write a few words...
-
After an episode dedicated to weight loss of his popular day time show, Dr. Oz began to see a series of online banners with his picture promoting a meal replacement shake. The banner claims that the...
-
The results of the particle-size analysis of a soil are as follows: Percent passing the No. 10 sieve = 100 Percent passing the No. 40 sieve = 80 Percent passing the No. 200 sieve = 68 The liquid...
-
1. A thin plastic rod of length L and charge Q is lying on an x axis as shown. The rod has a non-uniform linear charge density given by =20 (1- 1-1). A) Find the constant in terms of Q and L. P B)...
-
Audra owns a rental house. She makes mortgage payments of $1.410 per month, which include insurance, and pays $2.880 per year in property taxes and maintenance. Utilities are paid by the renter....
-
What is the mean radius from the midpoint of a cylinder withradius a and height h to its boundry surface?Evaluate the integral at a =h/2 =10cm
-
Players A, B, and C toss a fair coin in order. The first to throw a head wins. What are their respective chances of winning?
-
Use the following expressions to demonstrate that integer division yields an integer result: a) 8 / 4 b) 7 / 5
-
Repeat Exercise 25.38 using the values 7 and 9. Exercise 25.38 Test each of the two equality and four relational operators on the two values 7 and 7. For example, 7 == 7, 7 < 7, etc.
-
In Exercise 19.10 , you implemented the recursivequicksort algorithm. Reimplement the quicksort using the Fork/Join Framework. Exercise 19.10 The basic algorithm seems simple enough, but how do we...
-
When two clerks share the same cash register, it is a violation of which internal control principle? a. Establish responsibilities b. Maintain adequate records. c. Insure assets. d. Bond key...
-
The most serious limitation of internal control is a. Computer error. b. Human fraud or human error. c. Cost-benefit principle. d. Cybercrime. e. Management fraud.
-
Jack Delaney is the accountant responsible for customer accounts in the accounts receivable subsidiary ledger. What duty will a good internal control system withhold from Delaney? Why?
Study smarter with the SolutionInn App