Class 12 IT(802) – Java MCQs with Answers | CBSE Complete Revision
🔥 Crack Java with Exam-Focused MCQs!
This Class 12 IT (802) Java MCQ collection is carefully curated to cover every important question pattern you can expect in the board exam. From concept-based questions to Find the Output, Find the Error, and competency-based MCQs, we’ve covered different varieties so that no important corner of Java is left untouched.
Java carries 20 marks in the Class 12 IT board examination, making it one of the most scoring sections. A strong command of Java MCQs can give you a significant advantage and help you aim for a high score in the board exam.
Q1. IDE Stands for
a) Integrated Developer Environments
b) Integrated Development Environments
c) Internal Developer Environments
d) Internal Development
Q2. Java source code is translated by the Java compiler into
a) machine language directly
b) HTML
c) Java bytecode
d) SQL
Q3. The component that translates Java bytecode into machine code and executes it is
a) JVM
b) IDE
c) Scanner
d) NetBeans editor
Q4. In NetBeans, a new project is started using
a) File > New Project
b) Run > New Project
c) Tools > Compile
d) Windows > Output
Q5. The Projects tab in NetBeans is used to view the
a) source/project organization
b) runtime exceptions only
c) keyboard settings
d) SQL result only
Q6. A Java comment beginning with // is normally used for
a) single-line comments
b) multiple-line comments only
c) declaring a package
d) declaring a class
Q7. Which syntax is generally preferred for a multiple-line comment in the text?
a) // … //
b) /* … */
c) ## … ##
d) <!– … –>
Q8. A package in Java is described in the text as a group of
a) related classes
b) variables only
c) loops only
d) operators only
Q9. The class name in the sample Java source file should be the same as the
a) package name
b) source file name
c) method name
d) variable name
Q10. The special method that every Java application must have is
a) start()
b) main()
c) run()
d) execute()
Q11. The standard statement used in the text to display output with a newline is
a) System.out.print()
b) System.out.println()
c) System.print()
d) Console.println()
Q12. The major difference between print() and println() is that println()
a) adds a newline after output
b) cannot print Strings
c) prints only numbers
d) requires a package
Q13. A variable is best described as
a) a fixed keyword
b) a placeholder/storage location for data
c) a compiler warning
d) a package
Q14. The data type of total\_marks in the percentage example is
a) double
b) char
c) int
d) boolean
Q15. The data type used for fractional marks in the example is
a) int
b) double
c) char
d) byte
Q16. In println(“Percentage = “+percentage), the + operator is used to
a) compare values
b) concatenate text and the variable value
c) divide the values
d) declare the variable
Q17. A local variable is available
a) throughout every Java program
b) only inside the method where it is declared
c) only inside the package
d) only inside the JVM
Q18. Java supports how many primitive data types in the table?
a) 6
b) 7
c) 8
d) 10
Q19. Which primitive type stores a single character?
a) String
b) char
c) boolean
d) float
Q20. Which primitive type represents True or False?
a) boolean
b) char
c) byte
d) double
Q21. A variable name may begin with
a) a digit only
b) alphabetic character, underscore or dollar sign
c) a space
d) a reserved word
Q22. Which variable name is valid according to the text?
a) total marks
b) int
c) total\_marks
d) 2marks
Q23. Java is
a) case-insensitive
b) case-sensitive
c) space-sensitive only
d) keyword-insensitive
Q24. Which statement can declare several variables of the same type?
a) int num1, num2, num3;
b) int num1 num2 num3;
c) integer num1,num2,num3;
d) int(num1,num2,num3);
Q25. A char literal is enclosed in
a) double quotes
b) single quotes
c) curly braces
d) square brackets
Q26. A String literal is enclosed in
a) single quotes
b) double quotes
c) parentheses
d) angle brackets
Q27. Which operator returns the remainder of integer division?
a) /
b) %
c) *
d) –
Q28. Which operator increases an operand by 1?
a) —
b) ++
c) +=
d) %=
Q29. Which operator checks equality?
a) =
b) ==
c) !=
d) <=
Q30. Which relational operator checks that two values are not equal?
a) <>
b) !=
c) =
d) !
Q31. Which logical operator is true only when both conditions are true?
a) ||
b) &&
c) !
d) %
Q32. Which logical operator is true when either condition is true?
a) &&
b) ||
c) !
d) ==
Q33. The statement a += b is equivalent to
a) a = b-a
b) a = a+b
c) a = a*b
d) a = a/b
Q34. The statement a %= b stores
a) the quotient
b) the remainder
c) the sum
d) the product
Q35. The switch statement is especially suitable for
a) matching one value among many possible values
b) repeating until a condition changes
c) declaring variables
d) reading files
Q36. The purpose of break in a switch case is to
a) terminate the switch
b) repeat the case
c) declare a variable
d) start a loop
Q37. Java provides which three looping statements in the text?
a) while, do-while and for
b) if, switch and for
c) try, catch and finally
d) class, object and method
Q38. A while loop tests its condition
a) after the body
b) before the body
c) only after termination
d) never
Q39. A do-while loop tests its condition
a) before the body
b) after the body
c) only at compile time
d) inside main only
Q40. Which loop always executes its body at least once?
a) while
b) do-while
c) for with false condition
d) none
Q41. A while loop can execute
a) zero or more times
b) exactly once
c) only twice
d) at least twice
Q42. The loop for (count=5; count<10; count++) executes
a) 4 times
b) 5 times
c) 6 times
d) 10 times
Q43. A semicolon is required after the condition in
a) while
b) do-while
c) for
d) if
Q44. An array is used to store
a) multiple values of the same type
b) only one value
c) only methods
d) only packages
Q45. The first index of a Java array is
a) 0
b) 1
c) -1
d) n
Q46. For an array of size n, the last valid index is
a) n
b) n+1
c) n-1
d) 1
Q47. For double[] marks = new double[5], the valid indices are
a) 1 to 5
b) 0 to 5
c) 0 to 4
d) 1 to 4
Q48. The property that gives an array’s size is
a) size
b) length
c) count
d) capacity
Q49. For marks.length equal to 5, the loop condition to visit every element is
a) i <= marks.length
b) i < marks.length
c) i > marks.length
d) i == marks.length
Q50. A static method can be called
a) without an invoking object
b) only through Scanner
c) only from a constructor
d) only after import
Q51. What is the output?public class Test {public static void main(String[] args) {System.out.print("Hello");System.out.print("Java");}}Java
a) Hello Java
b) HelloJava
c) JavaHello
d) Hello
Q52. What is the output?public class Test {public static void main(String[] args) {System.out.println("A");System.out.println("B");}}
a) AB
b) A B
c) A and B on separate lines
d) B then A
Q53. Find the error.public class Test {public static void main(String[] args) {System.out.println("Welcome")}}
a) No error
b) Missing semicolon
c) Wrong package
d) Wrong JVM
Q54. What is printed?int a = 20, b = 30;System.out.println(a + b);
a) 2030
b) 50
c) 10
d) 600
Q55. What is printed?int a = 20, b = 30;System.out.println(a % b);
a) 0
b) 10
c) 20
d) 30
Q56. Find the error.int total marks = 400;
a) No error
b) Space is not allowed in a variable name
c) int cannot be used
d) 400 is a String
Q57. What is printed?int a=20, b=30;a += b;System.out.println(a);
a) 20
b) 30
c) 50
d) 600
Q58. What is printed?int a=20, b=30;a *= b;System.out.println(a);
a) 50
b) 600
c) 10
d) 0
Q59. What is printed?int x=1;if (x==1)System.out.println("YES");elseSystem.out.println("NO");
a) YES
b) NO
c) 1
d) Error
Q60. What is printed?int p=35;if (p>=40)System.out.println("PASSED");elseSystem.out.println("FAILED");
a) PASSED
b) FAILED
c) 35
d) Nothing
Q61. What is printed?int p=55;if ((p>=40)&&(p<60))System.out.println("II");if (p>=60)System.out.println("I");
a) I
b) II
c) I II
d) Nothing
Q62. What is printed?int day=5;String s="";switch(day){case 5: s="Friday"; break;default: s="Incorrect Day!";}System.out.println(s);
a) Friday
b) Incorrect Day!
c) 5
d) Nothing
Q63. What is printed?int day=10;String s="";switch(day){case 5: s="Friday"; break;default: s="Incorrect Day!";}System.out.println(s);
a) Friday
b) Incorrect Day!
c) 10
d) Error
Q64. How many times does the body execute?int n=6;while(n<=5){System.out.println(n);n++;}
a) 0
b) 1
c) 5
d) 6
Q65. What is printed?int n=1;do{System.out.print(n);n++;}while(n<=3);
a) 123
b) 0123
c) 1234
d) 321
Q66. What is printed?for(int n=3;n>=1;n--)System.out.print(n);
a) 123
b) 321
c) 210
d) 333
Q67. What is printed?for(int n=1;n<=7;n=n+2)System.out.print(n+" ");
a) 1 2 3 4 5 6 7
b) 1 3 5 7
c) 2 4 6
d) 7 5 3 1
Q68. What happens?int n=1;while(n<=5){System.out.println(n);}
a) Prints 1 to 5
b) Prints nothing
c) Infinite loop
d) Compiler error
Q69. What is printed?double[] a={10,20,30};System.out.println(a.length);
a) 2
b) 3
c) 30
d) 0
Q70. Find the runtime error.double[] a={10,20,30};System.out.println(a[3]);
a) No error
b) ArrayIndexOutOfBoundsException
c) Compile-time package error
d) Infinity
Q71. What is printed?double[] a={10,20,30};for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");
a) 0 1 2
b) 10 20 30
c) 10 20
d) 20 30 10
Q72. What is returned?static double area(double l,double b){return l*b;}System.out.println(area(5,4));
a) 9
b) 20
c) 1
d) 25
Q73. What is printed?static void msg(String s){System.out.println("Message: "+s);}msg("Hi");
a) Hi
b) Message: Hi
c) s
d) Error
Q74. What happens in the given code?class Book{Book(String t){ }}Book b=new Book();
a) Creates object normally
b) Compiler complains because arguments are missing
c) Calls default constructor
d) Creates a String
Q75. What happens in the give code?class Book{private double price=200;}Book b=new Book();System.out.println(b.price);
a) 200
b) 0
c) Cannot access private member outside class
d) Infinity
Q76. What is printed?String s="Hello World";System.out.println(s.equalsIgnoreCase("hello world"));
a) true
b) false
c) 11
d) Error
Q77. What is printed?String s="Hello World";System.out.println(s.replace('l','*'));
a) He**o Wor*d
b) Hello World
c) H**lo World
d) He**o World
Q78. Assertion (A): A do-while loop executes its body at least once. Reason (R): Its condition is tested after the loop body.
a) A and R are true; R explains A
b) A and R are true; R does not explain A
c) A is true; R is false
d) A is false; R is true
Q79. Assertion (A): An array of size 5 has index 5 as a valid index. Reason (R): Java array indexing starts at 0.
a) A and R are true; R explains A
b) A and R are true; R does not explain A
c) A is true; R is false
d) A is false; R is true
Q80. Assertion (A): A constructor has the same name as its class. Reason (R): A constructor has no return type.
a) A and R are true; R explains A
b) A and R are true; R does not explain A
c) A is true; R is false
d) A is false; R is true
Q81. Assertion (A): Private data members can be accessed directly from outside the class. Reason (R): Private visibility is restricted to the class.
a) A and R are true; R explains A
b) A and R are true; R does not explain A
c) A is true; R is false
d) A is false; R is true
Q82. Assertion (A): Getter and setter methods can provide controlled access to private data. Reason (R): A setter can validate a new value before assigning it.
a) A and R are true; R explains A
b) A and R are true; R does not explain A
c) A is true; R is false
d) A is false; R is true
Q83. Assertion (A): Integer.parseInt() can convert a numeric String to int. Reason (R): The method is static and belongs to Integer.
a) A and R are true; R explains A
b) A and R are true; R does not explain A
c) A is true; R is false
d) A is false; R is true
Q84. Assertion (A): finally is executed only when an exception occurs. Reason (R): finally is used for cleanup and is executed when the try block exits.
a) A and R are true; R explains A
b) A and R are true; R does not explain A
c) A is true; R is false
d) A is false; R is true
Q85. A student gets an ArrayIndexOutOfBoundsException while processing five marks. Which correction is most appropriate?
a) Use i <= 5
b) Use i < marks.length
c) Start i at 1 and stop at 5
d) Use marks[5]
Q86. A method only displays a message and returns no value. Which return type should be used?
a) double
b) void
c) int
d) char
Q87. A program should sort student names alphabetically before displaying them. Which library feature from the text is appropriate?
a) Arrays.sort()
b) String.equals()
c) Scanner.next()
d) Integer.parseInt()
Q88. A programmer wants a case-insensitive comparison of two names. Which String method is most suitable?
a) equalsIgnoreCase()
b) equals()
c) contains()
d) replace()
Q89. A program needs the first occurrence of ‘W’ in “Hello World”. Which method fits?
a) indexOf(‘W’)
b) charAt(‘W’)
c) contains(‘W’)
d) length(‘W’)
Q90. A program may divide by zero during user input. Which construct should be introduced to handle the runtime problem?
a) try-catch
b) switch
c) for
d) package
Q91. A program should always perform cleanup when a try block exits. Which block is designed for this?
a) finally
b) catch
c) case
d) default
Q92. A school wants a prebuilt class before any class definition in the file. Which statement is used?
a) import
b) package
c) return
d) finally
Q93. A student wants a variable name that clearly communicates its purpose and follows the text’s naming guidance. Which is best?
a) x
b) a1
c) total\_marks
d) tm?mark