Comments in Java Source Files Flashcards

1
Q

What happens when you write a string in Java without enclosing it in double quotes?

a) The string is treated as a keyword
b) The string is treated as a symbol or variable, causing an error
c) The string is ignored by the compiler
d) The string is automatically converted to a variable

A

b) The string is treated as a symbol or variable, causing an error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In Java, what does the term ‘argument’ refer to?

a) A line of code that contains an error
b) A type of variable used only in functions
c) An input passed into a function for it to operate on
d) A keyword that defines a class

A

c) An input passed into a function for it to operate on

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you turn a line of code into a comment in Java?

a) By placing it within parentheses
b) By removing any variables from the line
c) By enclosing the line in double quotes
d) By using specific syntax to mark it as a comment

A

d) By using specific syntax to mark it as a comment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of using comments in Java code?

a) To execute code faster
b) To give additional information or context about what the code does
c) To prevent code from being executed
d) To resolve syntax errors

A

b) To give additional information or context about what the code does

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of comments in Java?

a) To increase program performance
b) To display additional information to the user
c) To convey information to the code reader without being executed
d) To add extra functionality to the program

A

c) To convey information to the code reader without being executed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you indicate a single-line comment in Java?

a) By placing the text inside parentheses
b) By using two consecutive forward slashes (//)
c) By enclosing the text in double quotes
d) By using curly braces {}

A

b) By using two consecutive forward slashes (//)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What happens if there is executable code before a comment marked with // in Java?

a) The entire line is ignored, including the code
b) The code before the // is executed, but the comment is ignored
c) Only the comment is executed
d) It causes a syntax error

A

b) The code before the // is executed, but the comment is ignored

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you create a multi-line comment in Java?

a) By using double quotes around the comment text
b) By starting with /* and ending with */
c) By using three consecutive forward slashes (///)
d) By placing the text inside parentheses

A

b) By starting with /* and ending with */

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the purpose of commenting out code during the development phase?

a) To improve the performance of the code
b) To allow the developer to remove code permanently
c) To prevent certain lines from being executed without deleting them
d) To introduce syntax errors

A

c) To prevent certain lines from being executed without deleting them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens if a multi-line comment in Java is not closed properly?

a) The program will run as normal
b) Everything following the comment will be treated as part of the comment
c) The code will execute partially
d) The compiler will ignore the incomplete comment

A

b) Everything following the comment will be treated as part of the comment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why is it recommended to use comments for big-picture understanding rather than specific details?

a) Specific details can confuse the developer
b) Code should be clear enough that detailed comments aren’t necessary
c) Comments increase the execution time
d) Specific details are only needed for junior developers

A

b) Code should be clear enough that detailed comments aren’t necessary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In the example given, which line of code will be executed if only line 5 is uncommented?

1 public class MyFirstProgram {
2 public static void main(String[] args) {
3 System.out.println(“Hello World”);
4 System.out.println(“Welcome to Java Programming”);
5 System.out.println(“Java is a high-level programming language”);
6 }
7 }

a) System.out.println(‘Hello World’);
b) System.out.println(‘Welcome to Java programming’);
c) System.out.println(‘Java is a high-level programming language’);
d) None of the lines will be executed

A

c) System.out.println(‘Java is a high-level programming language’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly