MCQ- SET-1
1. Which among the following feature is not in the general definition of OOPS?
a) Modularity
b) Efficient Code
c) Code reusability
d) Duplicate or Redundant Data
2. Which feature of OOPS derives the class from another class?
a) Inheritance
b) Data hiding
c) Encapsulation
d) Polymorphism
3. Which two features of object-oriented programming are the same?
a) Abstraction and Polymorphism features are the same
b) Inheritance and Encapsulation features are the same
c) Encapsulation and Polymorphism features are the same
d) Encapsulation and Abstraction
4. Which of the following feature is also known as run-time binding or late binding?
a) Dynamic typing
b) Dynamic loading
c) Dynamic binding
d) Data hiding
5. Which member of the superclass is never accessible to the subclass?
a) Public member
b) Protected member
c) Private member
d) All of the mentioned
6. Encapsulation is_____?
a) technique of combining more than one member functions into a single unit.
b) mechanism of combining more than one data member into a single unit.
c) mechanism of combining more than one data members and member functions
that implement on those data members into a single unit
d) technique of combining more than one data members and member functions into
a single unit, which can manipulate any data.
7. Predict the output
public class Solution{
public static void main(String[] args){
byte x = 127;
x++;
x++;
System.out.print(x);
}
}
a) -127
b) 127
c) 129
d) 2
8. Select the valid statement.
a) char[] ch = new char(5)
b) char[] ch = new char[5]
c) char[] ch = new char()
d) char[] ch = new char[]
9. Find the output of the following program.
public class Solution{
public static void main(String[] args){
int[] x = {120, 200, 016};
for(int i = 0; i < x.length; i++){
System.out.print(x[i] + “ “);
}
}
}
a) 120 200 016
b) 120 200 14
c) 120 200 16
d) None
10. Identify the correct restriction on static methods.
I. They must access only static data
II. They can only call other static methods.
III. They cannot refer to this or super.
a) I and II
b) II and III
c) Only III
d) I, II and III
11. Identify the keyword among the following that makes a variable belong to a
class,rather than being defined for each instance of the class.
a) final
b) static
c) volatile
d) abstract
12. In which of the following is toString() method defined?
a) java.lang.Object
b) java.lang.String
c) java.lang.util
d) None
.
13. What does the following string do to given string str1.
String str1 = “Interviewbit”.replace(‘e’,’s’);
a) Replaces single occurrence of ‘e’ to ‘s’.
b) Replaces all occurrences of ‘e’ to ‘s’.
c) Replaces single occurrence of ‘s’ to ‘e’.
d) None.
14. How many objects will be created in the following?
String a = new String(“Interviewbit”);
b = new String(“Interviewbit”);
Strinc c = “Interviewbit”;
String d = “Interviewbit”;
a) 2
b) 3
c) 4
d) None
15. Find the output of the following code.
if(1 + 1 + 1 + 1 + 1 == 5){
System.out.print(“TRUE”);
}
else{
System.out.print(“FALSE”);
}
a) TRUE
b) FALSE
Compile error
None
16. Identify the modifier which cannot be used for constructor.
a) public
b) protected
c) private
d) static
17, What is the variables declared in a class for the use of all methods of the class
called?
a) Object
b) Instance variables
c) Reference variable
d) None
18. Identify the prototype of the default constructor.
Public class Solution {}
a) Solution(void)
b) Solution()
c) public Solution(void)
d) public Solution()
19. In which of the following is toString() method defined?
a) java.lang.Object
b) java.lang.String
c) java.lang.util
d) None
20. Which component is used to compile, debug and execute the java programs?
a) JRE
b) JIT
c) JDK
d) JVM
21. What will be the output of the following Java program?
1. class output {
2. public static void main(String args[])
3. {
4. double a, b,c;
5. a = 3.0/0;
6. b = 0/4.0;
7. c=0/0.0;
8.
9. System.out.println(a);
10. System.out.println(b);
11. System.out.println(c);
12. }
a) NaN
b) Infinity
c) 0.0
d) all of the mentioned
22. What will be the error in the following Java code?
byte b = 50;
b = b * 50;
a) b cannot contain value 50
b) b cannot contain value 100, limited by its range
c) No error in this code
d) * operator has converted b * 50 into int, which can not be converted to byte without casting
23. What is the numerical range of a char data type in Java?
a) 0 to 256
b) -128 to 127
c) 0 to 65535
d) 0 to 32767
24. Which of the following can be operands of arithmetic operators?
a) Numeric
b) Boolean
c) Characters
d) Both Numeric & Characters
25. Which of the following can be operands of arithmetic operators?
a) Numeric
b) Boolean
c) Characters
d) Both Numeric & Characters
26. What will be the output of the following Java code?
1. class Output
2. {
3. public static void main(String args[])
4. {
5. int x , y = 1;
6. x = 10;
7. if (x != 10 && x / 0 == 0)
8. System.out.println(y);
9. else
10. System.out.println(++y);
11. }
12. }
a) 1
b) 2
c) Runtime error owing to division by zero in if condition
d) Unpredictable behavior of program
27. What will be the output of the following Java code?
1. class operators
2. {
3. public static void main(String args[])
4. {
5. int var1 = 5;
6. int var2 = 6;
7. int var3;
8. var3 = ++ var2 * var1 / var2 + var2;
9. System.out.print(var3);
10. }
11. }
a) 10
b) 11
c) 12
d) 56