NEW
Font size
WorksheetsTopic 4 Quiz ITP
Total questions: 9
Worksheet time: 5mins
Which of the following is the correct syntax for a single-line comment in Java?
#This is a comment
// This is a comment
/* This is a comment */
<! - - This is a comment - ->
What is the purpose of comments in Java code?
To increase the execution speed of the program
To provide explanations or annotations for the code
To define variables
To handle exceptions
Which access modifier allows a member to be accessible only within its own class
public
protected
private
default
If no access modifier is specifies for a class member, what is the default access level?
public
protected
private
package-private (default)
What is a block in Java
A single line of code
A group of statements enclosed in braces {}
A comment section
A method declaration
Which of the following is true about blocks in Java
Blocks can be used to define the scope of variables
Blocks are only used in loops
Blocks are optional in method definitions
Block cannot be nested
Which of the following is the correct way to define a class in Java
class Myclass { }
public Myclass { }
MyClass Class { }
define class MyClass { }
What is the purpose of class in Java
To define a blueprint for objects
To execute a block of code repeatedly
To handle exceptions
To perform arithmetic operations
Why is the main method declared as static in Java
To allow the JVM to invoke it without creating an instance of the class
To enable method overloading
To restrict its access to the class only
To allow it to return a value
