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
-
4. An instant lottery game gives you probability 0.02 of winning on any one play. Plays are independent of each other. (a) Draw and label a tree diagram for all the possible outcomes of playing the...
-
1. Explain four events or trends that may impact whether or not organisational objectives are achieved.
-
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.
-
The scalar function div(grad 1) = f (also written 2f) is called the Laplacian, and a function f satisfying 2f = 0 is said to be harmonic, concepts important in physics. Show that 2f = fxx + fyy +...
-
Discuss the use of different Information Systems to support management at various levels. Also discuss the role and importance of Enterprise Applications to managing large organizations. do fast and...
-
Some investment professionals refer to LIFO inventory valuation as an earnings management tool, suggesting that LIFO allows a company to create a hidden earnings reserve on a companys balance sheet,...
-
At December 31, 2015, certain accounts included in the property, plant, and equipment section of Townsand Companys balance sheet had the following balances: Land............ $ 100,000...
-
Required information Use the following information to answer Problems 45-47 (Algo) [The following information applies to the questions displayed below.] Washington County's Board of Representatives...
-
Company A is a global company based in the United States that operates in the financial industry. Company A serves its customers with financial products, such as checking accounts, bank cards, and...
-
What is the minimum filing requirement for income in Pennsylvania? Pennsylvania gross Leif lived and worked in Nebraska until May 1, 2022, when he purchased a home and moved to Pennsylvania to start...
-
Write a method named two DimSearch that searches a 2D array row by row sequentially and prints out the row and column number of every occurrence of the value val if the array contains the requested...
-
The following information is available to reconcile Branch Company's book balance of cash with its bank statement cash balance as of July 31. a. On July 31, the company's Cash account has a $25,691...
-
in java we have a class which is using a jfilechooser which has the following methods in them uploadcsv, displaycsvcontent and save csv but when we upload the csv we are not able to see the content...
-
I need help with a mergers and acquisitions proforma document 75% Debt Pro-Forma Target Buyer NewCo Book Value Mkt Value Book Value Mkt Value 12/31/2018 12/31/2018 12/31/2018 12/31/2018 12/31/2018...
-
A small, sticky piece of clay, with a mass of 194 grams, is stuck onto the outer rim of an album with a diameter of 30 cm. If the album is spinning at 4 rad/s, what is the magnitude of the paper...
-
On June 1, 2025, Bonita contracted with Black Construction to have a new building constructed for $4,720,000 on land owned by Bonita. The payments made by Bonita to Black Construction are shown in...
-
True & False The basis of an asset must be reduced by the depreciation allowable, 2. Adjusted gross income (AGI) is the basis for a number of phase-outs of deductions. 3. A change to adjusted gross...
-
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...
-
On December 31, 2017, Brown Company issued \(\$ 750,000\) of 20 -year, eight percent bonds payable for \(\$ 621,307\), yielding an effective interest rate of ten percent. Interest is payable...
-
On December 31, 2017, Shade Company issued \(\$ 250,000\) of 20 -year, eight percent bonds payable for \(\$ 276,694\), yielding an effective interest rate of seven percent. Interest is payable...
-
Matt Enterprises issued \(\$ 200,000\) of ten percent, five-year bonds with interest payable semiannually. Determine the issue price if the bonds are priced to yield (a) ten percent, (b) six percent,...
Study smarter with the SolutionInn App