Font size
WorksheetsJava Basics, operators and variables (CH/PT)
Total questions: 16
Worksheet time: 5mins
What does System.out.println() do?
Takes user input
Outputs text to the console
Ends a program
None of the above
Which keyword is used to define a class in Java?
class
define
struct
object
What is the purpose of the public keyword in Java?
It hides the method or class from other classes.
It allows the method or class to be accessed from outside.
It specifies that the method is private.
None of the above.
Which of the following is a correct way to declare a variable in Java?
int 1x = 10;
int x = 10;
integer x = 10;
num x = 10;
Which data type is used to store a single character in Java?
char
String
int
boolean
What will be the value of the variable z after executing the code below? int x = 5, y = 10; int z = x + y;
5
10
15
50
What will be the result of the following code? int a = 10, b = 3; System.out.println(a % b);
1
3
10
0
Which operator is used to increment a value by 1 in Java?
--
++
+=
**
What does the != operator do in Java?
Checks if two values are equal.
Checks if two values are not equal.
Assigns a value to a variable.
Negates a Boolean value.
Variables in Java must start with a letter or an underscore.
TRUE
FALSE
Java uses double slashes (//) for multi-line comments.
TRUE
FALSE
The main method is the entry point of a Java program.
TRUE
FALSE
Which line of code will output the sum of 7 and 19?
System.out.print(7 + 19);
System.out.print("7 + 19");
system.out.print(7 + 19);
System.out.print(7 + 19)
What is the extension of java code files?
.class
.java
.txt
.js
What will be the output of this code?
class Codechef {
public static void main(String[] args) {
System.out.print(82);
System.out.print(2);
System.out.print(" 3");
} }
What will be the output of this code?
class Codechef {
public static void main(String[] args) {
int a = 10 ;
int b = 3 ;
int c = a / b;
System.out.print(c); } }
3.333
3
4
a / b
