Quiz
Quiz
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following principles is applied when you design a system with
simple, modular components that can easily be extended?
a.
Data hiding
b.
Extensibility
c.
KISS
d.
DRY
e.
Polymorphism
Question 2
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the default value of an instance variable of type boolean in Java?
a.
undefined
b.
false
c.
true
d.
0
e.
null
Question 3
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the default value of an array element in a String[] array?
a.
null
b.
false
c.
"" (empty string)
d.
undefined
e.
0
Question 4
Correct
Mark 1.00 out of 1.00
Flag question
Question text
How can you achieve data hiding in a Java class?
a.
By using abstract methods
b.
By using private instance variables and providing public getters and setters
c.
By using multiple inheritance
d.
By making all variables public
e.
By creating complex methods
Question 5
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What will be the output of the following code? class Test { static int a = 10;
Test() { a += 5; } public static void main(String[] args) { Test t1 = new Test();
Test t2 = new Test(); System.out.println(a); }
a.
10
b.
20
c.
None of the above
d.
Compile error
e.
15
Question 6
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the key benefit of the KISS (Keep It Simple, Stupid) principle?
a.
Making the code modular
b.
Keeping the code simple and easier to maintain
c.
Making the code difficult to understand
d.
Writing long and complex methods
e.
Reducing the system’s performance
Question 7
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which keyword is used to refer to the current instance of a class?
a.
current
b.
object
c.
this
d.
super
e.
instance
Question 8
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the default value of a boolean in Java?
a.
null
b.
true
c.
false
d.
1
e.
0
Question 9
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What will the following code output? int x = 5; x = x > 3 ? x + 1 : x - 1;
System.out.println(x);
a.
Compile error
b.
7
c.
6
d.
5
e.
4
Question 10
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the correct syntax to initialize a 1D array in Java?
a.
int[] arr = new int[3];
b.
int[] arr = new int[]{1,2,3};
c.
int[] arr; arr = {1,2,3};
d.
int[] arr = {1,2,3};
e.
All of the above
Question 11
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following is a benefit of using method overriding?
a.
It makes the code more complex
b.
It allows private methods to be accessed by subclasses
c.
It prevents a method from being called in a subclass
d.
It allows subclasses to inherit methods from the superclass
e.
It enables a subclass to change the behavior of an inherited method
Question 12
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What does System.out.println(true ? "A" : "B"); print?
a.
B
b.
True
c.
None of the above
d.
False
e.
A
Question 13
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the result of System.out.println("Java".charAt(2));?
a.
J
b.
v
c.
Compile error
d.
None of the above
e.
a
Question 14
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following is true about method overriding in Java?
a.
The overriding method can have a different return type than the method in the
superclass
b.
The overriding method can only be private
c.
The overriding method must be static
d.
The overriding method must have a different name from the superclass method
e.
The overriding method must have the same signature as the method in the
superclass
Question 15
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of these is NOT a valid primitive data type?
a.
long
b.
byte
c.
double
d.
short
e.
integer
Question 16
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which statement is true about an instance variable in Java?
a.
It can be accessed from static methods without an object reference.
b.
It must be initialized before it can be used.
c.
It must always be declared as public.
d.
It is shared among all instances of a class.
e.
It is automatically initialized to null for non-object types.
Question 17
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the output of the following code? int[] arr = {1, 2, 3};
System.out.println(arr.length == 3 ? "Correct" : "Incorrect");
a.
Correct
b.
False
c.
Compile error
d.
True
e.
Incorrect
Question 18
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following access modifiers ensures that a class member is
accessible only within the package?
a.
protected
b.
default
c.
static
d.
public
e.
private
Question 19
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What does data abstraction in OOP allow you to do?
a.
Make code more complex
b.
Remove the need for classes
c.
Hide implementation details while showing only the necessary functionality
d.
Expose all implementation details to the user
e.
Combine all methods in one class
Question 20
Incorrect
Mark 0.00 out of 1.00
Flag question
Question text
What will the following code output?
a.
25
b.
35
c.
20
d.
30
e.
15
Question 21
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following best defines composition in Java?
a.
A class inherits methods from multiple classes
b.
A class contains only static fields and methods
c.
A relationship where a class contains instances of another class
d.
A relationship where classes are independent of each other
e.
A relationship where a class extends another class
Question 22
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the primary use of a setter method?
a.
To delete a field.
b.
To return an object.
c.
To return the value of a field.
d.
To create a new field.
e.
To set the value of a field.
Question 23
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which method is used to find the length of a string in Java?
a.
str.getLength();
b.
str.capacity();
c.
str.size();
d.
str.len();
e.
str.length();
Question 24
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which operator is used to compare two values in Java?
a.
==
b.
>
c.
!=
d.
=
e.
<
Question 25
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following is a valid switch case statement for a char type?
a.
switch("A") { case 'A': break; }
b.
switch('A') { case 'A': break; }
c.
switch('A') { case 65: break; }
d.
switch('A') { case A: break; }
e.
switch(A) { case 'A': break; }
Question 26
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What will the following code output?
a.
10 5 2 0
b.
10 5 2 1
c.
10 5 3 1
d.
5210
e.
521
Question 27
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of these is not a valid loop in Java?
a.
Switch loop
b.
While loop
c.
Do-while loop
d.
For loop
e.
For-each loop
Question 28
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the output of the following code? System.out.println(3 != 2 ? "Not
equal" : "Equal");
a.
True
b.
False
c.
Compile error
d.
Not equal
e.
Equal
Question 29
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What will the following code print? int n = 5; System.out.println(n % 3 == 0 ?
"Divisible" : "Not Divisible");
a.
Not Divisible
b.
Compile error
c.
0
d.
5
e.
Divisible
Question 30
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which loop is used to iterate over elements in an array?
a.
While loop
b.
For-each loop
c.
Do-while loop
d.
For loop
e.
Switch loo