MCQ AP PRACTICE EXAM 1A COMPUTER SCIENCE A
Consider the following code segment.
int a = 3 + 2 * 3;
int b = 4 + ;
int c = 7 % 4 + 3;
double d = a + b + c;
What is the value of d after the code segment is executed? - Answers- C) 20.0
Consider the following code segment. Assume num is a properly declared and initialized
int variable.
if (num > 0)
{
if (num % 2 == 0)
{
System.out.println("A");
}
else
{
System.out.println("B");
}
}
Which of the following best describes the result of executing the code segment? -
Answers- D) When num is a positive even integer, "A" is printed; when num is a positive
odd integer, "B" is printed; otherwise, nothing is printed.
Consider the following implementation of getHours.
public static double getHours(int marker1, int marker2)
{
/* missing statement */
return hours;
}
Which of the following statements can replace /* missing statement */ so getHours
works as intended? - Answers- C) double hours = Math.abs(marker1 - marker2) / 60.0;
Consider the following class definition.
public class Bird
{
private String species;
private String color;
private boolean canFly;
public Bird(String str, String col, boolean cf)
{
species = str;
, color = col;
canFly = cf;
}
}
Which of the following constructors, if added to the Bird class, will cause a compilation
error? - Answers- E) public Bird(String col, String str, boolean cf)
{
species = str;
color = col;
canFly = cf;
}
Which of the following expressions evaluate to 3.5 ?
I. (double) + 3
II. (double) () + 3
III. (double) ( + 3) - Answers- A) I only
Consider the following code segment.
int num = /* initial value not shown */;
boolean b1 = true;
if (num > 0)
{
if (num >= 100)
{
b1 = false;
}
}
else
{
if (num >= -100)
{
b1 = false;
}
}
Which of the following statements assigns the same value to b2 as the code segment
assigns to b1 for all values of num ? - Answers- E) boolean b2 = (num < -100) || (num >
0 && num < 100);
Consider the following class definition.
public class Points
{
private double num1;
private double num2;
public Points(int n1, int n2) // Line 6
{
Consider the following code segment.
int a = 3 + 2 * 3;
int b = 4 + ;
int c = 7 % 4 + 3;
double d = a + b + c;
What is the value of d after the code segment is executed? - Answers- C) 20.0
Consider the following code segment. Assume num is a properly declared and initialized
int variable.
if (num > 0)
{
if (num % 2 == 0)
{
System.out.println("A");
}
else
{
System.out.println("B");
}
}
Which of the following best describes the result of executing the code segment? -
Answers- D) When num is a positive even integer, "A" is printed; when num is a positive
odd integer, "B" is printed; otherwise, nothing is printed.
Consider the following implementation of getHours.
public static double getHours(int marker1, int marker2)
{
/* missing statement */
return hours;
}
Which of the following statements can replace /* missing statement */ so getHours
works as intended? - Answers- C) double hours = Math.abs(marker1 - marker2) / 60.0;
Consider the following class definition.
public class Bird
{
private String species;
private String color;
private boolean canFly;
public Bird(String str, String col, boolean cf)
{
species = str;
, color = col;
canFly = cf;
}
}
Which of the following constructors, if added to the Bird class, will cause a compilation
error? - Answers- E) public Bird(String col, String str, boolean cf)
{
species = str;
color = col;
canFly = cf;
}
Which of the following expressions evaluate to 3.5 ?
I. (double) + 3
II. (double) () + 3
III. (double) ( + 3) - Answers- A) I only
Consider the following code segment.
int num = /* initial value not shown */;
boolean b1 = true;
if (num > 0)
{
if (num >= 100)
{
b1 = false;
}
}
else
{
if (num >= -100)
{
b1 = false;
}
}
Which of the following statements assigns the same value to b2 as the code segment
assigns to b1 for all values of num ? - Answers- E) boolean b2 = (num < -100) || (num >
0 && num < 100);
Consider the following class definition.
public class Points
{
private double num1;
private double num2;
public Points(int n1, int n2) // Line 6
{