public class Star { private int mySize; private double myDistance; private String…
- User
public class Star { private int mySize; private double myDistance; private String myName; public Star() { mySize = 0; myDistance = 0; myName = "none"; the following attempts to create a Star Object. I. Star s = new Star(15, 25.9, Vega); II. Star s = new Star(); III. Star s = new Star(11, 14.25, "Rigel"); Which line of code above does NOT compile? } public Star(int s, double d, String n) { mySize = s; myDistance = d; A. II. B. I. myName = n; } public double getDistance() { return myDistance; } public double getInfo() { return mySize / 2. myDistance; + } public int calc(int m) { int xm 5; + return x; C. III.
- Assistant
The line that does NOT compile is:
B. I.
Explanation: The reason is that when passing arguments to the constructor in line I, the string argument is not enclosed in double quotes. The correct syntax for creating a
Starobject with a name should include the name as a string literal:Star s = new Star(15, 25.9, "Vega");Thus, line I has incorrect syntax and will result in a compilation error. Here's a corrected version of each mentioned line for clarity:
- Correct line I (as intended but with syntax error):
Star s = new Star(15, 25.9, "Vega");- Line II (compiles correctly, calls the no-arg constructor):
Star s = new Star();- Line III (compiles correctly, correctly calls the constructor with arguments):
Star s = new Star(11, 14.25, "Rigel");Therefore, the choice is B. I.
- User
Given the object declaration: House h = new House("1 Main", 490000, 19, true); Which of the following lines of code do NOT compile? I. double q1= h.getAnswer(3.1415); II. double q1= getAnswer(4); III. int w = h.decide("true"); A. II. and III. B. II. only C. I. only
- Assistant
Without seeing the actual definitions for the
getAnswerand methods of the class, we have to make assumptions based on common practices and conventions in Java. - User
Which of the following lines of code does NOT compile? A. PlayableCharacter pc = new PlayableCharacter(Al, "Ice", -2, false); B. PlayableCharacter pc = new PlayableCharacter("CS", -0.5, 0, !true); C. PlayableCharacter pc = new PlayableCharacter();
- Assistant
To determine which line of code does not compile, we need to consider the standard rules of Java syntax and the common practices for constructors in object-oriented programming. Specifically, the correctness of each line hinges on whether the constructors being invoked match a defined constructor signature in the class. Without the explicit constructor definitions from that class, we have to make some general assumptions based on typical Java programming conventions: