Tutorials References Exercises Videos Menu
Log in
Free Website Get Certified Upgrade

Java Quiz Results

Score: 19 of 25

76% Correct:


Question 1:

What is a correct syntax to output "Hello World" in Java?

System.out.println("Hello World");    Your answer  
echo("Hello World");
print ("Hello World");
Console.WriteLine("Hello World");

Question 2:

Java is short for "JavaScript".

False    Your answer  
True

Question 3:

How do you insert COMMENTS in Java code?

// This is a comment    Your answer  
/* This is a comment
# This is a comment

Question 4:

Which data type is used to create a variable that should store text?

String    Your answer  
myString
Txt
string

Question 5:

How do you create a variable with the numeric value 5?

int x = 5;    Your answer  
float x = 5;
x = 5;
num x = 5

Question 6:

How do you create a variable with the floating number 2.8?

float x = 2.8f;    Your answer  
byte x = 2.8f
x = 2.8f;
int x = 2.8f;

Question 7:

Which method can be used to find the length of a string?

getLength()    Your answer  
getSize()
len()
length()    Correct answer  

Question 8:

Which operator is used to add together two values?

The + sign    Your answer  
The * sign
The & sign

Question 9:

The value of a string variable can be surrounded by single quotes.

True    Your answer  
False    Correct answer  

Question 10:

Which method can be used to return a string in upper case letters?

toUpperCase()    Your answer  
upperCase()
tuc()
touppercase()

Question 11:

Which operator can be used to compare two values?

==    Your answer  
><
=
<>

Question 12:

To declare an array in Java, define the variable type with:

[]    Your answer  
{}
()

Question 13:

Array indexes start with:

0    Your answer  
1

Question 14:

How do you create a method in Java?

methodName()    Your answer  
methodName.
methodName[]
(methodName)

Question 15:

How do you call a method in Java?

methodName();    Your answer  
methodName;
methodName[];
(methodName);

Question 16:

Which keyword is used to create a class in Java?

class    Your answer  
class()
className
MyClass

Question 17:

What is the correct way to create an object called myObj of MyClass?

new myObj = MyClass();    Your answer  
class MyClass = new myObj();
class myObj = new MyClass();
MyClass myObj = new MyClass();    Correct answer  

Question 18:

In Java, it is possible to inherit attributes and methods from one class to another.

False    Your answer  
True    Correct answer  

Question 19:

Which method can be used to find the highest value of x and y?

Math.maximum(x,y)    Your answer  
Math.maxNum(x,y)
Math.max(x,y)    Correct answer  
Math.largest(x,y)

Question 20:

Which operator is used to multiply numbers?

*    Your answer  
%
x
#

Question 21:

Which keyword is used to import a package from the Java API library?

package    Your answer  
import    Correct answer  
getlib
lib

Question 22:

How do you start writing an if statement in Java?

if (x > y)    Your answer  
if x > y then:
if x > y:

Question 23:

How do you start writing a while loop in Java?

while (x > y)    Your answer  
while x > y:
while x > y {
x > y while {

Question 24:

Which keyword is used to return a value inside a method?

return    Your answer  
get
break
void

Question 25:

Which statement is used to stop a loop?

break    Your answer  
return
exit
stop

Kickstart your career

Get certified by completing a course

Get certified w3schools CERTIFIED . 2022