OBJECT ORIENTED PROGRAMMING USING JAVA QUIZ 1.1

 OBJECT ORIENTED PROGRAMMING USING JAVA QUIZ 1.1


What will happen when you compile and run the following code?

public static void main(String[] args){
int i = 0;
for(i = 100; i >= 0; i -= 10 ){
System.out.print(i + ", ");
}
}

a. 100, 90, 80, 70, 60, 50, 40, 20, 10,
b. 100, 90, 80, 70, 60, 50, 40, 20, 10, 0
c. 90, 80, 70, 60, 50, 40, 20, 10, 0,
d. None of the above


What will be the output of the following program?

public class Main {
public static void main(String[] args){
for(int i = 0 ; i < 10; i++){
}
System.out.println(i);
}
}

a. Compilation Error
b. 9
c. 11
d. 10


What is method overriding in Java?
a. Writing a method in a subclass with the same name of superclass’s method
b. Mentioning the same return type of the method of the superclass
c. The argument list in the method of subclass and the method of superclass should be the same
d. All of the above


What is the output of the following program?

public static void main(String[] args){
for(char c = 'a' ; c < 'd'; c++){
System.out.print(c);
}
}

a. .Code will print 012
b. .Code will print abc
c. None of the above
d. Code will not compile


What is not a type of Java for-statement?
a. Labeled for statement
b. for-else statement
c. Simple for-statement
d. for-each statement or extended for-statement


What will happen when you compile and run the following code?

public static void main(String[] args){
for(int i = 0; i < 10; i++){
if(i % 2 == 0)
continue;
System.out.println(i);
}
}

a. None of the above
b. Code will print all even numbers between 0 to 10
c. Code will not compile
d. Code will print all odd numbers between 0 to 10

See also  OBJECT ORIENTED PROGRAMMING USING JAVA QUIZ 1.2

What will be the output of the following program?

public static void main(String[] args){
int i = 0;
for(; i < 10; i++){
break;
}
System.out.println(i);
}
}

a. Compilation Error
b. 0
c. 10
d. 1


Which statements are true about labeled for-statement?
a. Labeling is generally used with break and continue statements.
b. We can provide a label to a for-loop to identify uniquely when multiple loops are used in nested formation.
c. Labels are just to decorate for-statements
d. Both A & B


for is _____ statement in java.
a. iteration or looping
b. All of the above
c. decision-making
d. branching


Which statement is Incorrect?
a. for loop must be used when the number of iteration is not fixed, it is recommended to use for loop.
b. for loop is a control flow statement that iterates a part of the program multiple times
c. | for(init;condition;incr/decr){ // code to be executed } | is for loop syntax
d. for loop must be used when the number of iteration is fixed, it is recommended to use for loop.