wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

TGT APCSA Spring

Total questions: 34

Worksheet time: 18mins

Name
Class
Date
1.

What are the primitive data types?

a)

int, double, boolean

b)

int,double,boolean, String

c)

int, float, boolean

d)

integer, boolean, doubly

2.

What does the following code print?

System.out.print("9 ");

System.out.println("+ 5 = 14");

a)

error

b)

9 + 5 = 14

c)

9

+ 5 = 14

d)

9+5+14

3.

What is 4 + 3 * 2?

a)

error

b)

2

c)

14

d)

10

4.

What does the following code do?

chips *= 7;

a)

"chips" is equal to 7

b)

Multiplies the value of "chips" by 1 and stores the result in "chips"

c)

Adds 7 to "chips"

d)

Multiplies the value of "chips" by 7 and stores the result in "chips".

5.

What does it mean for a value to be declared as final?

a)

final is not in java

b)

It can only be changed

c)

It cannot be changed.

d)

it is the final answer to the problem

6.

What does modulo do?

a)

returns the dividend

b)

divides the numbers

c)

returns the remainder

d)

divides with an integer result

7.

What is 8 % 3?

a)

2

b)

0

c)

1

d)

3

8.

What is the difference between truncating and rounding?

a)

Truncating is not done in Java

b)

Truncating does not change the whole number portion, while rounding may change the whole number portion.

c)

Truncating is the same as Rounding

d)

Truncating changes the whole number and Rounding cuts off the decimal

9.

What is 6 % 4 + 9?

a)

11

b)

19

c)

6

d)

2

10.

What does the following code print?

System.out.print("Hi ");

System.out.print("friend");

a)

Hi friend

b)

Hi

friend

c)

Hifriend

d)

friend Hi

11.

What does \t do?

a)

adds a backspace

b)

adds a tab

c)

goes to the next line

d)

adds a title

12.

Data type for non return method is

a)

int

b)

double

c)

void

d)

public static

13.
How do you make an instance of the Animal class?
a)
Animal anim = new Animal();
b)
Animal = new Animal();
c)
Animal anim = new Animal;
14.

How do you call a method named orderUp() from the Chef class using a Chef object called boyardee?

a)

boyardee.orderUp()

b)

orderUp(boyardee)

c)

.orderUp(boyardee)

d)

boyardee.orderUp(boyardee)

15.

What will be printed by the following line of code?

System.out.println("\"ice bear\"");

a)

"ice bear"

b)

ice bear

c)

""ice bear""

d)

"\"ice bear\""

16.

How do you define an array called arr that holds 7 ints?

a)

int[ ] arr = new int[seven];

b)

int arr = new arr[7];

c)

int[ ] arr = new int[7];

d)

int [ ] arr = new array int[7];

17.

Which index is the last element in an array called chips?

a)

chips.length()

b)

chips.length - 1

c)

chips.length

d)

chips.length()-1

18.
What are the legal indexes for the array ar, given the following declaration:
int[] ar = {2, 4, 6, 8 }
a)
 0, 1, 2, 3
b)
 1, 2, 3, 4
c)
2, 4, 6, 8
d)
 0, 2, 4, 6
19.

/* 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?

a)

int y

boolean z

b)

int y

double z

c)

int y

int z

d)

double y

double z

20.

For the array:

int stats[3];

What is the range of the index?

a)

0 to 3

b)

0 to 2

c)

1 to 3

d)

0 to 4

21.
What value is at index 1 in this array?  String[] names = {"Mack", "Dennis", "Dee", "Charlie"};
a)
Mack
b)
Dennis
c)
Dee
d)
Charlie
22.

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);

a)

[4, 3, 1, 6]

b)

[5, 3, 1, 6]

c)

[4, 3, 6]

d)

[4, 5, 3, 6]

23.

What index value is used to locate the last element in the nums ArrayList?

a)

nums.size()-1

b)

nums.length()-1

c)

nums.size()

d)

nums.length

24.

Which statement is the correct declaration and initialization of an ArrayList of String values?

a)

ArrayList<String> name;

name = new ArrayList<String>();

b)

ArrayList name;

name = new ArrayList<String>();

c)

ArrayList<String> name;

name = ArrayList<String>();

d)

String<ArrayList> name;

name = new String<ArrayList>();

25.
How do you get the number of elements in an ArrayList called "list" in Java?
a)
list.size();
b)
list.count();
c)
list.length();
d)
list.getSize();
26.

Which statement below is the correct way to retrieve the first element in the nums ArrayList?

a)

nums.get(0)

b)

nums[0]

c)

nums(0)

d)

nums[1]

27.

Given the nums ArrayList with the values [5, 4, 3, 2], what statement below removes the value 3 from the list?

a)

nums.remove(2)

b)

nums.remove(3)

c)

nums.get(2) = null

d)

nums.remove(1)

28.

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?

a)

nums.add(4, 5)

b)

nums.add(5, 4)

c)

nums.add(5, 5)

d)

nums.add(5)

29.
Inheritance is used when the relationship between two classes is a(n) _______ relationship.
a)
"HAS-A"
b)
"PART-OF-A"
c)
"IS-A"
d)
inverse
30.
In the main method:
public static void main(String args[])
What does public accomplish?
a)
The method will be accessible by any Class
b)
The given method or variable is not instance related but Class related
c)
The method will not return any value
d)
Method name is searched by JVM as a starting point for an application
31.

The following Syntax is used for?


class Subclass-name extends Superclass-name

{

//methods and fields

}

a)

Polymorphism

b)

Encapsulation

c)

Inheritance

d)

None of the above

32.

A class that is inherited is called a ______ .

a)

superclass

b)

Subclass

c)

subsetclass

d)

Relativeclass

33.

Which Java statement represents inheritance?

a)

class body inherit Car

b)

class body super Car

c)

class body extends Car

d)

class body this Car

e)

class body override Car

34.

super keyword is used to access

a)

only subclass methods

b)

parent class variables and methods

c)

subclass variables and methods

d)

only parent class methods