Font size
WorksheetsJava - Quiz 3
Total questions: 24
Worksheet time: 18mins
What is the correct output?
a) true
true
false
true
b) true
false
true
true
c)false
false
true
true
d)false
true
true
false
condition ? expression1 : expression2;
if condition is true, expression2 is executed.
a) true
b) false
PREDICT THE OUTPUT:
int x = 60;
int y = 90;
if (y%x == 0 && y-x==30){
System.out.println("Hello World"); }
else{
System.out.println("Error"); }
a) Hello World
b) Error
c) Hello world
d) Hello World
Error
When the variable being switched on is equal to a case, the statements following that case will execute until a _ statement is reached.
a) continue;
b) break;
c) default;
d) go;
Which data types are allowed in a Java switch statement?
a) int, short, byte, double, char
b) String, int, short, char
c) char, byte, short, int, String
d) String, int, byte
What option describes button number 5 on the toolbar?
a) Step over an expression
b) Step over
c) Step into
d) Step out of
which is the Default format of LocalDateTime?
a) 2014-04-28
b) 2014-04-28T23:25:49.342Z
c) 2014-04-28T16:25:49.341
d) 28::Apr::2014
int [ ] [ ] numbers = new int [ 8 ][ 7 ]
which option is correct?
a) 7 arrays of 8 elements each
b) 8 arrays of 7 elements each
How many times will the following code print "Welcome to Java"?
int count = 0;
while (count < 10) {
System.out.println("Welcome to Java");
count++; }
a) 11
b) 9
c) 8
d) 10
What is the output of the following code?
int x = 0;
while (x < 4) {
x = x + 1; }
System.out.println("x is " + x);
a) x is 3
b) x is 2
c) x is 4
d) x is 0
The following loop displays _.
for (int i = 1; i <= 10; i++) {
System.out.print(i + " ");
i++; }
a) 1 2 3 4 5 6 7 8 9
b) 1 2 3 4 5 6 7 8 9 10
c) 1 3 5 7 9
d) 1 2 3 4 5
How many times is the println statement executed?
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
System.out.println(i * j);
a) 10
b) 100
c) 1
d) 1000
What will be displayed when the following code is executed?
int number = 6;
while (number > 0) {
number -= 3;
System.out.print(number + " "); }
a) 6 3
b) 3 3
c) 6 6
d) 3 0
What is the correct function of a while loop?
a) To consume the initialization, condition and increment/decrement in one line
b) To check for condition after executing the statements
c) A control flow statement that allows code to be executed repeatedly based on a given Boolean condition.
d) To initialize the variable in use.
a) Compilation error
b)"Loop" will be printed infinite times
c) "Loop" will be printed once
d) No output
which is correct order?
1- Use to iterate indefinitely through statements and to perform the statements zero or more times.
2- Use to iterate through the elements of an Array or ArrayList.
3- Use to iterate indefinetely through statements and to perform the statements one or more times.
4- Use to step through statements a predefined number of times.
a) 1- do/while
2-enhanced for
3-while
4-for
b) 1- do/while
2-while
3-for
4-enhanced for
d) 1-for
2- do/while
3-enhanced for
4-while
d) 1-while
2-enhanced for
3-do/while
4-for
Which is correct?
a) ArrayList<int> arrayList = new ArrayList<>();
b) ArrayList<Integer> arrayList = new ArrayList<>();
a)
b)
a) I eat dog food
I can bark
b) I can eat
I can bark
is a class which inherits the other class
a) Super Class
b) Sub Class
c) Class
Is when a subclass implements a method that already has an implementation in the superclass
a) extends
b) inheritance
c) overriding
d) hierarchy
e) polymorphism
Represents the IS-A relationship
a) Polymorphism
b) Inheritance
c) Reusability
d) Hierarchy
An interface is a kind of template for building classes.
Can a class implement one or more interfaces?
a) true
b) false
What are the valid statements for static keyword in Java?
a) We can have static block in a class.
b) The static block in a class is executed every time an object of class is created.
c) We can have static method implementations in interface.
d) We can define static block inside a method.
a) 2 and 3
b) 1 and 4
c) 1 and 3
d) 2 and 4
e) None of the above
