Font size
WorksheetsJava Basics Self-Check
Total questions: 46
Worksheet time: 24mins
Which of the following is a comment in the Java language?
/ comment /
//comment
/ comment */
<-- comment -->
Which of the following is the correct main() method signature in Java?
public static void main (String [] args)
public static void Main (String [] args)
public static void main (string [] args)
public static void main (String args)
Which of this command does not have errors?
System.out.print("Hello World")
System.out.print(Hello World);
System.out.Print("Hello World);
System.out.print("Hello World");
What will be output of below program?
public class Test {
public static void main(String[] args) {
int x = 10*20-20;
System.out.println(x);
}
}
Runtime Error
Prints 180
Prints 0
None of the above
What is the output for the following statement:
System.out.print("1"+"1");
11
2
Error Message
Indicate the actual output of the statements below:
int thisYear = 2020;
System.out.println("The current year is "+thisYear);
The current year is thisYear
The current year is 2020
No output; an error exists
The current year is
Which of the following is used as a terminator in Java programming?
)
;
.
>
int x= 10;
int y = 20;
int z = x + y;
System.out.println(z);
Guess the output.
1020
10 20
30
"10 20"
Which of this command has errors? Select multiple
System.out.print("Hello World")
System.out.print(Hello World);
System.out.Print("Hello World);
System.out.print("Hello World");
It is an optional statement used to describe what a program or a line of program is doing.
tag
command
code
comment
A data type which is typical in form and make use of digits and a decimal point
integer
float
char
boolean
What data type is classified as a sequenced of characters with double quotes.
Char
String
boolean
Float
True or False : Java is case sensitive, which means identifier Hello and hello would have different meaning in Java
True
False
Comment lines are not ignored by the compiler. True or False?
True
False
A variable that holds words
String
boolean
int
float
A dictionary
A variable that holds true or false
String
boolean
int
float
Alex Trebek
Name the data type: 1.0
double
int
char
boolean
Name the data type: "true"
boolean
char
String
double
Name the data type: false
String
boolean
int
None of the above
What data type would you use for storing the number of students in a class?
boolean
String
double
int
What data type would you use for storing the average test score in a class?
double
String
int
char
What data type would you use to store names of students?
String
char
boolean
None of these
blonde
How would you declare a variable storing the tax rate?
int taxRate = 5.1;
taxRate = "5.1";
double taxRate = 5.1;
double taxRate = "5.1";
I do hereby declare thee Sir Tax Rate
How would you declare a variable storing a person's name?
string name = "Elroy";
name String = "Elroy";
String name = Elroy;
String name = "Elroy";
Me llamo Elroy
How would you declare a variable that tells you that someone passed a class?
boolean passed = 'true';
boolean passed = true;
passed = true;
String passed = "true";
Trick question - no one passes this class
Which declaration will throw an error?
double num = 8;
int averageGrade = 89.7;
boolean done = false;
String done = "true";
What prints out "I love Java" successfully?
System.out.println(I love Java);
Systemoutprintln("I love Java);
System.out.println("I love" + " Java");
System.out.println("I love Java")
What is love? Baby dont hurt me. Dont hurt me. No more.
4 % 6
4
6
2
3
6 % 4
4
6
2
3
int a = 7;
int b = 2 + a;
b = 9
b = 2
b = 7
b = 5
int a = 5;
a++;
What is a now?
4
7
5
6
int a = 5;
a--;
What is a now?
4
3
5
6
What will print?
System.out.println( 1 / 4 );
0
0.25
1
4
What will print?
System.out.println( 1.0 / 4 );
0
0.25
1
4
What will print?
System.out.println( (double) 1 / 4 );
0
0.25
1
4
int x = 4;
x *= 10;
Which is true?
x is now 40
x is now 10
x is still 4
x is now 14
What is the value of b after this code segment?
int a = 4;
int b = a++;
a = a * 2;
b /= 2;
2
4
5
8
++ increases the value of a variable by 1
assignment operator
decrement operator
increment operator
sentinel
What's the value of below?
int i=5;
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
5
6
7
6
6
7
6
7
8
5
5
6
Which statement(s) are equivalent to i = i + 1?
i += 1
i++
i -= 1
i--
what is modulo operation used for ?
performs division
performs division and gives no remainder
performs division and gives remainder
does not perform division
arithmetic operators return a value. True or false?
true
false
conditional operators does not return a value
true
false
which type of operator it is? i + =5
addition assignment operator
conditional operator
arithmetic operator
equality operator
Find the output for the following.
public class IncDec
{
public static void main(String s[])
{
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.print("b = " + b);
System.out.println("c = " + c);
System.out.print("d = " + d);
}
}
a = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
