Category: Java quizzes

Java quiz 20: Convert from a class to interfaces

In this quiz InterfaceA extends InterfaceB. The class MyClass implements InterfaceA. The question is whether it is allowed to convert from MyClass to both interfaces and what the consequences would be. Java quiz 20: Convert from a class to interfaces Level: Normal What is written to the standard output as the result of executing the […]

Java quiz 19: Conditional statements

Let’s start with today’s simple quiz for beginners. Java quiz 19: Conditional statements Level: Easy What is written to the standard output as the result of executing the following code? Author: Sar Maroof Answer explanation The statement if(y > (x + 4) || (y – 3) == x) returns false, because y is not greater […]

Java quiz 18: A while loop & conditional statements

Here we have a combination of a while loop and a conditional statement. Java quiz 18: A while loop and conditional statements Level: Normal What is written to the standard output as the result of executing the following code? Author: Sar Maroof Answer explanation The boolean variable isActive is not initialized. Therefore its value is […]

Java quiz 17: Working with ArrayLists

ArrayList is used in Java to collect data. If you are not familiar with ArrayLists, you can read this article about ArrayList. Java quiz 17: Working with ArrayLists Level: Hard What is written to the standard output as the result of executing the following code? Author: Sar Maroof Answer explanation The statement ml1.list2 = ml1.method(ml1.list); […]

Java quiz 16: Ternary operator

Here is an example that shows how the ternary operator works in Java. Java quiz 16: Ternary operator Level: easy What is the output of this code? Author: Sar Maroof Answer explanation The statement int y = (x < 3) ? 4 : 8; means The statement if(x < 3) returns false, because x is […]

Java quiz 15: Loop within loop

For many of the projects on which I worked, I needed to use loops within loops. In the beginning seems very hard, but if you understand the process you become gradually familiar with it. Java quiz 15: Loop within loop Level: Hard What is the output of this code? Author: Sar Maroof Answer explanation If […]

Java quiz 14: Comparing strings

As a Java programmer you need very often to work with strings. Here is a simple quiz that shows the way Java handles strings. Java quiz 14: Comparing strings Level: Normal What happens when the following program is compiled and run?   Author: Sar Maroof Answer explanation The first conditional statement if (str1 == str2) […]

Java quiz 13: Working with while loop

This program is a simple while loop. Working with while loop is needed regularly for every Java programmers. Java quiz 13: Working with while loops Level: Easy What is written to the standard output as the result of executing the following code?   Author: Sar Maroof Answer explanation The initial value of i is 1. […]

Java quiz 12: Conditional statements

Here we have a sequence of conditional statements. Java quiz 12: A sequence of conditional statements Level: Normal What is written to the standard output as the result of executing the following code?   Author: Sar Maroof Answer explanation The condition if(!isActive) returns true, because the boolean variable isActive is false. The statement str += […]

Java quiz 11: While loop

The while loop is one of the types of loops in Java. Every advanced Java programmer see what happens in this program,  but unfortunately that doesn’t apply to beginners. Therefore, as a beginner programmer, you need to practice regularly to master that kind of loops. Java quiz 11: Practicing with while loop Level: Easy What is […]

Java quiz 10: Calling constructor from constructor

In this program we call a constructor within another constructor. Remember what happens when you create an object of a class that extends another class. Java quiz 10: Calling constructor from constructor Level: Normal What is written to the standard output as the result of executing the following code?             […]

Java quiz 09: How to handle exceptions?

As a programmer you need to know what kind of exceptions might occur in your code. By handling the exceptions, you would avoid problems for the users of your program. In the following example, passing some parameters to the method myMethod could cause exceptions. Therefore it is necessary to handle the exceptions that might occur. […]

Java quiz 08: Array elements

Here is a simple array of Strings with the length of 5. We assigned the values of all the elements of the array. If you are not familiar with arrays, you can read my article “Java arrays” before answering this quiz. Java quiz 8: Array elements Level: Normal What is written to the standard output […]

Java quiz 07: Working with arrays

Here is a simple array of Strings with the length of 4. We assigned values of some of the elements of the array. If you are not familiar with arrays, you can read my article “Java arrays” before answering this quiz. Java quiz 7: Working with Arrays Level: Normal What is written to the standard […]

Java quiz 06: Handling exceptions

Handling Exceptions is one of the important concepts in Java programming language. I try to make that concept clear in this simple program. If you are not familiar with Exceptions, I recommend to read my article “Java exception handling using easy exercises” before trying this quiz. Java quiz 6: Handling exceptions Level: Normal What is […]

Java quiz 05: Conditional statements else-if

I post three different levels of puzzles, quizzes and assignments to make sure that all the members benefit from my posts. Here is an easy quiz for beginners. To solve this quiz you need to understand the difference between the if sequences and the else if sequences, click here if you need to read my article […]

Java quiz 04: Overriding methods

Hi guys, Here is a Java quiz. If you can solve this quiz and understand the right explanation of the answer, you are really good in Java! Of course, I mean before you read the answer explanation below :-). Java quiz 4: Overriding methods Level: Hard What is written to the standard output as the result […]

Java quiz 03: Static and instance variables

It is important for every Java programmers to understand the difference between class(static) variables and instance variables. Therefore I wrote this quiz, which clarifies those differences. Java quiz 3: The difference between static and instance variables Level: Normal What is written to the standard output as the result of executing the following code? Author: Sar […]

Java quiz 02: Simple conditional statements

Here is a Java quiz about conditional statements. Look at the program carefully, because there is a difference between a sequences of if statements and a sequences of else if statments. If you don’t know that, please, read my article first by clicking here. Java quiz 2: Simple conditional statements Level: Easy What is written […]

Java quiz 01: Passing parameters to constructors

Hi guys, I would emphasize that understanding constructors helps you by initializing instance variables. In the following code, I try to make that concept clear. I use a trick to make it difficult to guess the result if you don’t understand the constructor block. Java quiz 1: Passing parameters to constructors Level: Normal What is […]

Sarmaroof © 2017