Question: In a for loop, what is the next step after the execution of the instructions in each iteration is completed? e.g. What is the next
In a for loop, what is the next step after the execution of the instructions in each iteration is completed?
e.g. What is the next step after System.out.println(i) ?
for (int i=0; i < 5; i++) {
System.out.println(i);
}
checking the condition
Jumping out of the loop
Initializing the counter variable
Updating the counter variable
In what type of loop statement can we manipulate and change the loops counter in the loops body?
For loop
While loop
Both a and b
We cannot do this in either one
What is the statement used in a decision-making process?
For loop
While loop
If else statement and else is mandatory
If else statement and else is not mandatory
How many else statements can be used in an if statement?
1
2
0
As many as needed
What is the output of the following code and what is the value of the variable i once the loop concludes and the control jumps out of the loop? (% is the remainder of the division)
int i = 1;
while (i < 10)
if (i % 2 > 0) {
System.out.println(i);
i++;
}
else
i += 3;
1, 3, 5, 7, 9 and i=9
1, 3, 5, 7, 9 and i=10
1, 5, 9 and i=9
1, 5, 9 and i=10
Which one is a method signature?
void calculateAge(int year, int month, int day)
int calculateAge(int year, int month, int day)
public int calCulateAge(int year, int month, int year)
public int calculateAge(int, int, int)
What will the following code print?
String printMe = Im here!;
void printMe() {
String printMe = Im there!;
System.out.println(printMe);
}
System.out.println(printMe);
Im here!
Im there!
Im here!
Im there!
Im there!
Im here!
A protected member of a class is only available in the scope of the class.
True
False
Which one is correct about an array in Java?
An array has a variable length.
The elements of the array can be of different data types.
array[length] returns the last element in the array.
Indexing in an array starts from 0.
Which feature of OOP describes the reusability of the code?
Polymorphism
Inheritance
Encapsulation
Abstraction
Which of the following OOP concepts binds the code and data together and keeps them secure from the outside world?
Polymorphism
Inheritance
Encapsulation
Abstraction
What is the size of the class?
Sum of the size of all the variables in the class.
Sum of the size of all the inherited variables with the variables of the same class.
The size of the largest variable in the class.
A class does not have a size.
Which of the following helps achieving the concept of encapsulation in a class?
Using inheritance
Defining all the members of the class as private
Using proper access modifiers
None of the above
Which of the following statements is incorrect?
An object is an instance of the class.
A Java class can have multiple constructors.
Object and its class have the same size in memory.
Private members of a class cannot be accessed by its objects.
What will the following code print?
class Test
{
public static void main(String args[])
{
for (int i = 0; i < 4; i++)
{
System.out.println(i);
}
System.out.println(i);
}
}
0
1
2
3
4
0
1
2
3
0
1
2
3
4
5
The code will not be compiled.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
