NEW
Font size
WorksheetsTGT APCSA Spring
Total questions: 34
Worksheet time: 18mins
What are the primitive data types?
int, double, boolean
int,double,boolean, String
int, float, boolean
integer, boolean, doubly
What does the following code print?
System.out.print("9 ");
System.out.println("+ 5 = 14");
error
9 + 5 = 14
9
+ 5 = 14
9+5+14
What is 4 + 3 * 2?
error
2
14
10
What does the following code do?
chips *= 7;
"chips" is equal to 7
Multiplies the value of "chips" by 1 and stores the result in "chips"
Adds 7 to "chips"
Multiplies the value of "chips" by 7 and stores the result in "chips".
What does it mean for a value to be declared as final?
final is not in java
It can only be changed
It cannot be changed.
it is the final answer to the problem
What does modulo do?
returns the dividend
divides the numbers
returns the remainder
divides with an integer result
What is 8 % 3?
2
0
1
3
What is the difference between truncating and rounding?
Truncating is not done in Java
Truncating does not change the whole number portion, while rounding may change the whole number portion.
Truncating is the same as Rounding
Truncating changes the whole number and Rounding cuts off the decimal
What is 6 % 4 + 9?
11
19
6
2
What does the following code print?
System.out.print("Hi ");
System.out.print("friend");
Hi friend
Hi
friend
Hifriend
friend Hi
What does \t do?
adds a backspace
adds a tab
goes to the next line
adds a title
Data type for non return method is
int
double
void
public static
How do you call a method named orderUp() from the Chef class using a Chef object called boyardee?
boyardee.orderUp()
orderUp(boyardee)
.orderUp(boyardee)
boyardee.orderUp(boyardee)
What will be printed by the following line of code?
System.out.println("\"ice bear\"");
"ice bear"
ice bear
""ice bear""
"\"ice bear\""
How do you define an array called arr that holds 7 ints?
int[ ] arr = new int[seven];
int arr = new arr[7];
int[ ] arr = new int[7];
int [ ] arr = new array int[7];
Which index is the last element in an array called chips?
chips.length()
chips.length - 1
chips.length
chips.length()-1
ar, given the following declaration:int[] ar = {2, 4, 6, 8 }0, 1, 2, 31, 2, 3, 40, 2, 4, 6/* data type 1 */ y = 3;
/* data type 2 */ z = 4.0;
Which of the following best describes the data types that should be used to replace/* data type 1 / and / data type 2 */ so that the code segment compiles without error?
int y
boolean z
int y
double z
int y
int z
double y
double z
For the array:
int stats[3];
What is the range of the index?
0 to 3
0 to 2
1 to 3
0 to 4
What is the list nums if it is initially [5, 3, 1] and the following code is executed?
nums.add(6);
nums.add(0, 4);
nums.remove(1);
[4, 3, 1, 6]
[5, 3, 1, 6]
[4, 3, 6]
[4, 5, 3, 6]
What index value is used to locate the last element in the nums ArrayList?
nums.size()-1
nums.length()-1
nums.size()
nums.length
Which statement is the correct declaration and initialization of an ArrayList of String values?
ArrayList<String> name;
name = new ArrayList<String>();
ArrayList name;
name = new ArrayList<String>();
ArrayList<String> name;
name = ArrayList<String>();
String<ArrayList> name;
name = new String<ArrayList>();
Which statement below is the correct way to retrieve the first element in the nums ArrayList?
nums.get(0)
nums[0]
nums(0)
nums[1]
Given the nums ArrayList with the values [5, 4, 3, 2], what statement below removes the value 3 from the list?
nums.remove(2)
nums.remove(3)
nums.get(2) = null
nums.remove(1)
Given the nums ArrayList with the values [1, 2, 3, 4, 6], what code below can be used to add a 5 between the 4 and 6 in the list?
nums.add(4, 5)
nums.add(5, 4)
nums.add(5, 5)
nums.add(5)
public static void main(String args[])What does public accomplish?
The following Syntax is used for?
class Subclass-name extends Superclass-name
{
//methods and fields
}
Polymorphism
Encapsulation
Inheritance
None of the above
A class that is inherited is called a ______ .
superclass
Subclass
subsetclass
Relativeclass
Which Java statement represents inheritance?
class body inherit Car
class body super Car
class body extends Car
class body this Car
class body override Car
super keyword is used to access
only subclass methods
parent class variables and methods
subclass variables and methods
only parent class methods
