Chapter 2 Quiz
#1:
Suppose you have the following Java code:
public class Hello { public static void main(String[] args) { System.out.println("hello world"); } }What should be the name of the file?
#2:
What do all statements end with in Java?
#3:
Where is the entry point for a Java program?.
#4:
What is the program exit code for a successful execution?
#5:
Does code inside a comment get executed?
Yes
No
#6:
How do you start a single-line comment in java?
#
--
//
/
#7:
What type of comment is this an example of?
/*
* This is a comment
*/
Single-line comment
Multi-line comment
Javadoc comment
TODO comment
#8:
What will the output of this main method be?
public static void main(String[] args) { // System.out.println("hello world"); }
No output
hello world
The program will crash
#9:
Which of the following is not one of the most common types of whitespace?
newlines
carriage returns
spaces
tabs
#10:
What is the output of this code?
public static void main(String[] args) { System.out.print("hello"); System.out.print("world"); }
hello world
helloworld
hello world
world
#11:
Would this statement compile?
System.out.println(" hello world ");
Yes
No
#12:
Would this statement compile?
system.out.printline("hello world");
Yes
No
#13:
Can a program with compilation errors execute?
Yes
No
#14:
Can a program with a logic-error execute?
Yes
No
#15:
Which line of source code did this compilation error occur on?
C:\Code\sandbox\src\Main.java:5:19 java: cannot find symbol symbol: method printLine(java.lang.String) location: variable out of type java.io.PrintStream