WorksheetsJAVA BASIC 3
Total questions: 35
Worksheet time: 50mins
In java programming
There must be at least two variables declared
All of the value must be integer
There must be a method called "main"
There must be two private classes
Choose the appropriate data type for this value: 5.5
int
double
boolean
string
If you want your condition to depend upon two conditions BOTH being true. What is the proper notation to put between the two Boolean statements
!
!!
&&
>
Which of the following is not a Java keyword
Integer
int
public
static
Choose the appropriate data type for this field isSwimmer
int
String
boolean
object
What is the output of
System.out.println("Hey");
System.out.println("World");
?
Hey
World
_
Hey
World_
Hey World_
HeyWorld_
What is the output of
System.out.print("Hey");
System.out.print("World");
?
Hey World_
Hey
World_
HeyWorld_
Hey
World
_
What is the output of
System.out.print("This");
System.out.println("That");
?
ThisThat_
This
That_
This
That
_
ThisThat
_
Choose the right statement
System.out.println(Abc)
System,out,println(Abc)
System.out.println("Abc")
System,out,println("Abc"):
System.out.println("Abc");
How do you print "Hello" in Java?
print "Hello";
System.print("Hello");
System out println("Hello");
System.out.print("Hello");
What is Java documentation?
A textbook that teaches you Java syntax
Line comments that tell you what a line of a program does
A document that provides information about a class, such as the methods it has
A journal of bugs and bug fixes in each version of your program
What do you call the first line of a method that declares a method?
method call
the title
method signature
method parameters
What does an int type variable store?
A whole number
A decimal point number
A true or false value
Text
What does a double type variable hold?
A whole number
A decimal point number
Text
A true or false value
What does a boolean type variable hold?
A whole number
A decimal point number
Text
A true or false value
What does a String type variable hold?
A whole number
A decimal point number
Text
A true or false value
What do you call a named block of statements?
class
method
object
variable
With what method does the execution of a program start?
main
static
public
start
What is the correct method signature for the main method?
public void main(String[] args)
public void main(String args)
public void static main(String args)
public static void main(String[] args)
What is the return type of the method with the signature:
public boolean isTired()
none
boolean
unspecified
static
What punctuation do you use to group related statements?
semicolon ;
curly braces { }
brackets [ ]
parentheses ( )
What punctuation do you use to indicate the end of a statement?
semicolon ;
curly braces { }
brackets [ ]
parentheses ( )
What would result in a syntax error?
System.out.print("hi");
System.out.println("hi");
System.out.print("hi);
System.out.print("hijhhj");
A
B
C
D
E
-5
0
13
-1
12
11
12
5
9
-4
Consider the following code segment:
Line 1: int a = 10;
Line 2: double b = 10.7;
Line 3: double c = a + b;
Line 4: int d = a + c;
Line 5: System.out.println(c + " " + d);
What will be output as a result of executing the code segment?
20 20
20.0 30
20.7 31
20.7 30.7
Nothing will be printed because of a compile-time error.
Consider the following code segment:
Line 1: int a = 10;
Line 2: double b = 10.7;
Line 3: int d = a + b;
Line 3 will not compile in the code segment above. With which of the following statements could we replace this line so that is compiles?
I. int d = (int) a + b;
II. int d = (int) (a + b);
III. int d = a + (int) b;
I
II
III
I and III
II and III
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
Similar to variables but have the same value throughout the program
Constants
Variables
Private
Public
Begins an end of the line comment; compiler knows to ignore these comments
/** **/
/
//**
//
Occur when the program compiles and executes but the output is not what you wanted/expected
Logic errors
Runtime errors
Syntax errors
Grammar errors
Logic error
Syntax error
Runtime error
Error that occurs while the program is running
Runtime error
Logic error
Syntax error
Executes the program file
Class
Main Method
Package
Compiler
