WorksheetsJava Final Review
Total questions: 50
Worksheet time: 49mins
Which command is written incorrectly?
putBall();
putball();
turnLeft();
takeBall();
What is a code comment?
A way to teach Karel a new word
A way to give notes to the reader to explain what your code is doing
A message to your teacher in code
A place to write whatever you want in your code
We use For loop ..........
We use While loop ..........
Which statement(s) are equivalent to i = i + 1?
i += 1
i++
i -= 1
i--
In Java, which keyword is used to refer to the parent class of a class?
parent
super
this
base
What keyword is used to inherit a class in Java?
extends
implements
inherits
uses
If a class has multiple methods having the same name but different in parameters, it is known as ____ overloading.
class
object
method
data
Bank tom = new Bank(5000.0);
Which is the class?
To create an object in java we use the keyword new.
True
False
TextBook english = new Textbook();
In the above snippet, TextBook is a _______.
Object
Data member
Member function
Class
A template for an object.
class
object
method
field
Which keyword is used to refer to the current object in a Java class?
this
current
super
self
What is a method?
A. A procedure that is defined by the user.
B. A keyword used to loop for a fixed amount of time.
C. A place where we can store data.
D. The type that is given to a variable.
What is a return value?
A. The value that a method prints to the screen.
B. The value that is inputted to a method.
C. The value that a user inputs to a program.
D. The value that a method outputs.
Why do we use methods in Java?
To make code easier to understand
To avoid repeated code
To simplify code
All of the above
What kind of error is a syntax error, where the code isn't written in proper Java?
compile-time error
runtime error
exception
SyntaxErrorException
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
What is the correct way to find the length of "txt" string?
int len = length(txt);
float len = txt.length();
int len = txt.length();
double len = length(txt);
In the following code, what is the name of the method?
public void squared(int num1)
public
void
squared
num1
double[ ] data = new double[10];
System.out.println(numArray.length);
Which of the following is true about the size of Arrays and ArrayLists in Java?
Arrays have a fixed size, while ArrayLists can dynamically grow.
Both Arrays and ArrayLists have a fixed size.
Both Arrays and ArrayLists can dynamically grow.
Arrays can dynamically grow, while ArrayLists have a fixed size.
How can we teach Karel new commands?
A. A for loop
B. A while loop
C. Define a new method
D. The run method
Say you want to write a program to have Karel to pick up all of the tennis balls in a location, but you don’t know how many tennis balls there are. Which control structure would you use?
An if statement
A for loop
A while loop
An if/else statement
What data type would you use to store names of students?
String
char
boolean
None of these
How would you declare a variable storing a person's name?
string name = "Jeff";
name String = "Jeff";
String name = Jeff;
String name = "Jeff";
How would you declare a variable that tells you that someone passed a class?
boolean passed = 'true';
boolean passed = true;
passed = true;
String passed = "true";
Which declaration will throw an error?
double num = 8;
int averageGrade = 89.7;
boolean done = false;
String done = "true";
Assume that x, y, and z have been declared as follows:
boolean x = true;
boolean y = false;
boolean z = true;
Which of the following expressions evaluates to true?
x && y && z
x && y || z && y
!(x && y) || z
!(x || y) && z
x && y || !z
What does a multi-line comment look like in Java?
/* Comment */
? Comment ?
Comment **
-Java Comment-
What does a single-line comment look like in Java?
//comment
\\comment
/*comment*/
/comment
The following code segment will print (a)
System.out.println(6 % 9);
What is the result of the expression 12−4/2.0 in Java?
4
4.0
10
10.0
What is the result of the expression 5+15/3∗2−8%3 in Java?
13
10
11
14
Can be accessed only by other members of their own class
Public
Private
Closed
Method
Can be accessed by other members outside their own class
Private
Public
Source Code
OOP
The (a) keyword is used to create methods that do not return a value in Java.
A(n) (a) method returns a value.
