MCQ JAVA
MCQ JAVA
Chapter 1 and 2
1. Name the programming technique that implements programs as an organised collection of interactive
objects.
a. Procedure Oriented Programming b. Modular Programming
c. Object Oriented Programming d. None of these
Ans. c. Object Oriented Programming
2. Name the characteristics of Object Oriented Programming that hides the complexity and provides a
simple interface.
a. Encapsulation b. Polymorphism
c. Abstraction d. Inheritance
Ans. c. Abstraction
3. Which among the following operator is used to access individual members of an object?
a. . (dot) b. + (plus)
c. – (minus) d. / (divide)
Ans. a. . (dot)
4. Which among the following modifier is used in a ‘class’?
a. public b. default
c. Both a and b d. None of these
Ans. c. Both a and b
5. Which among the following is a valid class name?
a. Simple Interest b. SimpleInterest
c. 1SimpleInterest d. Simple@Interest
Ans. b. SimpleInterest
6. Which among the following is a valid object name?
a. obj1 b. 1obj
c. Obj 1 d. Obj#1
Ans. a. obj1
7. Which among the following is a valid float literal?
a. 12.36f b. 12.36F
c. 12.36 d. Both a and b
Ans. d. Both a and b
8. Which among the following is a valid octal integer literal?
a. o178 b. 675
c. 0675 d. 0X675
Ans. c. 0675
9. Which among the following is a valid method of initialising?
a. boolean f=true; b. boolean f=True;
c. boolean f=’true’; d. None of these
Ans. a. boolean f=true;
10. Which among the following is not a punctuator?
a. ; semicolon b. , comma
c. : colon d. . dot
Ans. d. . dot
11. Which among the following is not a primitive data type?
a. int b. float
c. String d. char
Ans. c. String
12. What is the largest possible value that can be stored in short data type?
a. 215 b. 231
c. 27 d. 263
Ans. a. 215
COMPUTER MCQ2021 2
13. If a is of type int and b is of type float what would be the resultant data type of a+b?
a. int b. float
c. double d. short
Ans. b. float
14. Which among the following is not a valid error in Java?
a. Syntax errors b. Logical errors
c. Runtime errors d. Technical errors
Ans. d. Technical errors
15. Which among the following Scanner methods allows us to input a number with a decimal point?
a. nextInt() b. nextFloat()
c. nextDecimal() d. nextPoint()
Ans. b. nextFloat()
16. The output in BlueJ occurs in which window?
a. Console window b. Terminal window
c. Both a and b d. None of these
Ans. b. Terminal window
17. The input in BlueJ occurs in which window?
a. Console window b. Terminal window
c. Both a and b d. None of these
Ans. b. Terminal window
18. Assigning value to a variable during declaration is called.
a. Declaration b. Assignment
c. Initialisation d. None of these
Ans. c. Initialisation
19. Which among the following is used to represent singleline comment?
a. // b. /*
c. \\ d. <!—
Ans. a. //
20. Which among the following is a logical error?
a. Missing semicolon b. Mismatched braces in classes and methods.
c. Misspelled keywords and identifiers. d. Addition is required but subtraction is performed.
Ans. d. Addition is required but subtraction is performed.
21. Which among the following represents a syntax error?
a. Dividing an integer by zero. b. Accessing an element that is out of bounds of an array.
c. Trying to store a value which is incompatible to a certain datatype. d. Missing semicolon
Ans. d. Missing semicolon
22. If the data that is to take part in a calculation in a method is fixed, which form of input is necessary?
a. Initialisation b. Parameterised input
c. Scanner input d. None of these
Ans. a. Initialisation
23. In case you need to give a proper message (prompt string) before taking an input from the user, which
would be the most preferable method?
a. Parameterised input b. Initialisation
c. Scanner input d. None of these
Ans. c. Scanner input
24. Which among the following is not a primitive data type?
a. int b. short
c. String d. long
Ans. c. String
25. Name the operator that is used to allocate memory space for an object.
a. Dot b. new
c. Both a and b d. None of these
COMPUTER MCQ2021 3
Ans. b. new
26. What is the name given to a memory location called in Java?
a. Variable b. Constant
c. Data Type d. None of these
Ans. a. Variable
27. Which are the data types used in Java?
a. Primitive data type b. Composite data type
c. Both a and b d. None of these
Ans. c. Both a and b
28. How are the characteristics of an object represented in a class?
a. Data Members b. Member Functions
c. Access specifiers d. None of these
Ans. a. Data Members
29. Which among the following is used to change the state of an object?
a. Data Members b. Name of the class
c. Both a and b d. None of these
Ans. a. Data Members
30. How is encapsulation implemented in a program?
a. Using a class b. Using only Functions
c. Using only Variables d. None of these
Ans. a. Using a class
31. Information passed to a method through arguments is called _____________.
a. Message b. Variables
c. Numbers d. Data
Ans. a. Message
32. What among the following is not a component of a message?
a. An object identifier b. A method name
c. Arguments d. Data Members
Ans. d. Data Members
33. How many objects can you create from a class?
a. One b. Two
c. Three d. Any number
Ans. d. Any number
34. Unary operator requires ___ operand(s) to operate on.
a. 1 b. 2
c. 3 d. none of them
Ans a
35. Choose the value of y after evaluating the given expression:
y+=++y+y+y; when y=8.
a. 33 b. 24
c. 31 d. 20
Ans: a
36. Identify the name of '&&' operator:
a. Increment operator b. Logical operator
c. Ternary operator d. Relational operator
Ans: b
37. What is the function of the % operator?
a. divides one operand with another b. used to find percentage
c. gives the remainder of division d. none of the above
Ans: c
38. Choose the output of :
char res= 'F';
COMPUTER MCQ2021 4
int n= res;
n=n+5;
System.out.println(n+" "+res);
a. 25F b. 75 70
c. 75 F d. 145
Ans: c
39. What is the ASCII value of A?
a. 65 b. 64
c. 62 d. 97
Ans: a
40. Select the appropriate Java expression for ut+1/2at
a. u*t+1/2at b. u*t+1/2*a*t
c. ut+1/2at d. none of them
Ans: b
41. Name the casting shown by
int x=(int) b;
a. implicit b. explicit
c. both of them d. none of them
Ans: b
42. Choose the correct output of the following code:
System. out.println("BEEN");
System. out.print(" VERY ILL");
a. has BEEN VERY ILL
b. BEEN
VERY ILL
c. has BEEN
VERY WELL
d. None of them
Ans: b
43. System.out.println("Jelly"); Is an example of?
a. Assignment b. Method invocation
c. Object creation d. Increment
Ans: b
44. Which one of the following is given the highest preference?
a. && b. %
c. >= d. ++
Ans: d
45. If num=500;
int num,sum,n=600;
sum= (n+num)>2000?500:600;
System.out.println(sum);
a. 600 b. 500
c. 200 d. none of these
Ans: a
46. 'Type conversion' is also called
a. Type casting b. Type change
c. Type inversion d. None of these
Ans: a
47. What is the value of a when x=5?
a=5*x++;
a. 30 b. 25
c. 55 d. 50
COMPUTER MCQ2021 5
Ans: b
48. What is the ASCII value of b?
a. 66 b. 65
c. 98 d. 97
Ans: c
49. Choose the correct value of x, if x=3,y=7
x=x++++y;
a. 8 b. 6
c. 8 d. 2
Ans: a
50. What is the value of y when a=7
y=2*++a;
a. 14 b. 16
c. 20 d. 36
Ans: b
51. Choose the attributes required for class definition :
a. keyword class b. name of the class
c. both a and b d. none of them
Ans: c
B. State whether the following statements are True (T) or False (F).
1. Encapsulation refers to the art of hiding the complexities and giving a simple interface. F
2. Procedure Oriented Language follows top down approach. T
3. Java is an example of Object Oriented Language. T
4. Hiding the complexity and giving a simple interface is called Inheritance. F
5. Abstraction is same as encapsulation. F
6. An object is called a class factory. F
7. A class is an instance of an object. F
8. A class is a mechanism to implement encapsulation. T
9. Data members in a class is used to represent the characteristic of an object. T
10. The new operator is used to create an object. T
11. It’s a rule to have a classname beginning in capital letter. F
12. Scanner class is present in the java.lang package. F
13. Math.abs( ) is used to find the absolute value of a number. T
14. The return type of Math.sqrt( ) function is float. F
15. The fraction 1/2 will evaluate to 0.5. F
16. The continue statement in a switch block is used to avoid fall through. F
17. The default statement is essential in a switch block. F
18. The for loop is an entry controlled loop. T
19. The while loop is an exit controlled loop. F
20. The dowhile loop is generally used when the number of iterations is known. F
21. You can have only the for loop as the nested loops. F
Chapter 3
1. Once a function is defined, it can be invoked repeatedly. What is this feature called?
a. Interface b. Reusability
c. Restructuring d. All of these
Ans. b. Reusability
2. If a function does not return any value, its return type should be:
a. int b. noreturn
c. void d. empty
Ans. c. void
3. A function that computes a value and returned is called:
a. Computational function b. Manipulative function
c. Procedural function d. None of these
Ans. a. Computational function
4. A type of parameter that are used to identify what data is to be passed to a function is called:
a. Formal parameter b. Actual parameter
c. Both a and b d. None of these
Ans. a. Formal parameter
5. The parameter list in a function definition is called:
a. Function prototype b. Function signature
c. Both a and b d. None of these
Ans. b. Function signature
6. The first line of the function definition is called:
a. Function prototype b. Function signature
c. Both a and b d. None of these
Ans. a. Function prototype
7. The number of values that a function can return is:
a. 1 b. 2
c. 3 d. 4
Ans. a. 1
8. A local variable in a function has its scope:
a. Limited within the function b. Can be accessed anywhere within the same class
c. No limitation at all d. None of these
Ans. a. Limited within the function
9. Which among the following is a valid name for a function?
a. function b. 2function
c. fun in action d. fun#
Ans. a. function
COMPUTER MCQ2021 7
10. Which among the following is not a valid access specifier?
a. public b. private
c. partially d. protected
Ans. c. partially
Chapter 4