0% found this document useful (0 votes)
11 views6 pages

Java Programming Quiz Questions

The document consists of a series of multiple-choice questions related to Java programming concepts, including Object-Oriented Programming features, data types, control structures, and array handling. Each question presents four options, with the goal of testing knowledge on Java syntax, operators, and best practices. The questions cover fundamental topics essential for understanding Java programming.

Uploaded by

nandan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

Java Programming Quiz Questions

The document consists of a series of multiple-choice questions related to Java programming concepts, including Object-Oriented Programming features, data types, control structures, and array handling. Each question presents four options, with the goal of testing knowledge on Java syntax, operators, and best practices. The questions cover fundamental topics essential for understanding Java programming.

Uploaded by

nandan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q1. Which of the following is not a feature of Object-Oriented Programming?

[ ]
a) Encapsulation b) Inheritance c) Platform dependency d) Polymorphism
Q2. In Java, the smallest individual unit in a program is called [ ]
a) Statement b) Method c) Token d) Identifier
Q3. Which method is the entry point for a Java program? [ ]
a) public void start(String[] args) b) public static void main(String[] args)
c) public main(String args[]) d) static public void main(String args[])
Q4. Which symbol is used for single-line comments in Java? [ ]
a) /* comment */ b) // comment c) # comment d) <-- comment -->
Q5. Which escape sequence is used to insert a new line in Java? [ ]
a) \t b) \n c) \\ d) \r
Q6. Which of the following is not a primitive data type in Java? [ ]
a) int b) Boolean c) String d) float
Q7. Which operator has the highest precedence in Java? [ ]
a) ++ b) * c) = d) &&
Q8. Which loop in Java executes at least once, regardless of the condition? [ ]
a) for b) while c) do–while d) for–each
Q9. Which statement can be used to skip the current iteration of a loop? [ ]
a) break b) return c) continue d) exit
Q10. Which of the following correctly represents a ternary operator usage? [ ]
a) x ? y : z; b) (condition) ? value1 : value2; c) (a > b) = x : y; d) if ? else;
Q11. Java is a ______ programming language. [ ]
a) Procedural b) Object-Oriented c) Functional only d) Assembly-based

Q12. Which of the following is not a principle of OOP? [ ]


a) Encapsulation b) Inheritance c) Compilation d) Polymorphism
Q13. Which keyword is used to define a class in Java? [ ]
a) define b) class c) struct d) object

Q14. Which method is the entry point for a Java program? [ ]


a) start() b) run() c) main() d) execute()

Q15. Which statement correctly defines a main method? [ ]


a) public void main(String args) b) public static void main(String[] args)
c) static public int main(String[] args) d) main(String args[])
Q16. The smallest individual unit in a Java program is called a: [ ]
a) Statement b) Token c) Block d) Method
Q17. Which is not a Java token? [ ]
a) Keyword b) Identifier c) Operator d) Header file
Q18. Which of these is not a valid Java identifier? [ ]
a) _value b) $price c) 9number d) myValue

Q19. Which symbol starts a multi-line comment in Java? [ ]


a) /* b) // c) # d) <!--
Q20. Which escape sequence inserts a new line? [ ]
a) \t b) \n c) \b d) \r
Q21. Command line arguments in Java are stored in: [ ]
a) String args[] b) char args[] c) Object args[] d) List args[]
Q22. Which package is required to take user input with Scanner? [ ]
a) [Link].* b) [Link].* c) [Link].* d) [Link].*
Q23. Which method reads an integer using Scanner? [ ]
a) next() b) nextInt() c) getInt() d) readInt()
Q24. Java source files have the extension: [ ]
a) .jav b) .java c) .jv d) .class
Q25. Compiled Java bytecode files have the extension: [ ]
a) .byte b) .exe c) .class d) .java
Q26. Java statements end with: [ ]
a) : b) ; c) . d) /
Q27. Which of the following is an escape sequence for a tab? [ ]
a) \n b) \t c) \b d) \r
Q28. Which is the correct way to print “Hello” in Java? [ ]
a) print("Hello"); b) [Link]("Hello");
c) [Link]("Hello"); d) echo "Hello";
Q29. Which is not a primitive data type? [ ]
a) int b) boolean c) String d) double

Q30. Default value of int in Java is: [ ]


a) 0 b) null c) garbage value d) undefined
Q31. Default value of boolean in Java is: [ ]
a) true b) false c) 0 d) null

Q32. Which of the following declares a variable correctly? [ ]


a) int 1num; b) float rate; c) boolean true; d) char name;
Q33. A constant variable is declared using: [ ]
a) const b) final c) static d) immutable

Q34. Which data type is used for 64-bit integers? [ ]


a) int b) long c) float d) double
Q35. Which operator is used for assignment? [ ]
a) == b) := c) = d) <=

Q36. Which of the following is a reference data type? [ ]


a) char b) Boolean c) String d) int

Q37. Which is the correct way to format output in Java? [ ]


a) printf("x = %d", x); b) [Link]("x = %d", x);
c) print("x = %d", x); d) format("x = %d", x);

Q38. Type casting from int to double is called: [ ]


a) Widening b) Narrowing
c) Boxing d) Parsing

Q39. Type casting from double to int is called: [ ]


a) Widening b) Narrowing c) Wrapping d) Parsing

Q40. Which keyword defines class-level variables? [ ]


a) const b) final c) static d) volatile

Q41. Which symbol is used for modulus? [ ]


a) / b) % c) * d) //

Q42. Which operator increases value by 1 before use? [ ]


a) x++ b) ++x c) x-- d) --x

Q43. Which operator decreases value by 1 after use? [ ]


a) x-- b) –x c) x++ d) ++x

Q44. Relational operators return:


a) int b) Boolean c) double d) String
Q45. Which operator is used for logical AND?
a) & b) && c) || d) !

Q46. Which bitwise operator inverts all bits?


a) & b) ~ c) ^ d) !

Q47. Which of these is the ternary operator?


a) ? : b) if–else c) switch d) loop

Q48. What is the result of 5 / 2 in Java (int division)?


a) 2.5 b) 2 c) 3 d) 2.0

Q49. Which operator checks equality?


a) = b) == c) === d) !=

Q50. Which is not a valid literal?


a) 'A' b) "Hello" c) 12.34 d) truee

Q51. Which operator has the highest precedence?


a) ++ b) * c) = d) &

Q52. Which keyword makes a variable constant in value?


a) static b) final c) const d) immutable

Q53. Which operator is used for bitwise OR?


a) || b) | c) & d) ^

Q54. What is the size of float in Java?


a) 2 bytes b) 4 bytes c) 8 bytes d) 16 bytes

Q55. Which keyword refers to the current object?


a) this b) final c) super d) current

Q56. Which loop always executes at least once?


a) for b) while c) do–while d) foreach
Q57. Which statement stops loop execution?
a) continue b) break c) exit d) stop

Q58. Which statement skips to the next iteration?


a) break b) continue c) skip d) exit

Q58 The if statement requires:


a) a boolean expression b) a numeric value
c) a string d) no condition
Q59. Which keyword is optional in a switch statement?
a) case b) break c) default d) switch

Q60. What happens if you omit break in a switch case?


a) Compiler error b) Program stops c) Fall-through to next case d) Skips all cases
Q61. Which loop is best when the number of iterations is known?
a) while b) do–while c) for d) foreach
Q62. Which loop is used for collections and arrays?
a) for b) while c) do–while d) for-each

Q63. Which statement is true?


a) continue jumps to next case in switch b) break stops loop or switch
c) default in switch is compulsory d) if always needs else
Q64. Which of the following is the correct way to declare an array in Java?
A) int arr[5]; B) int[] arr = new int[5]; C) int arr[] = new int[5]; D) Both B and C

Q65. What is the default value of an uninitialized boolean array element?


A) true B) false C) null D) 0

Q65. In Java, arrays are stored:


A) On the stack B) On the heap C) In CPU registers D) In permanent storage

Q66. What will be the output?

int[] arr = {10, 20, 30};

[Link](arr[1]);

A) 10 B) 20 C) 30 D) Compilation error
Q66. Which exception is thrown if you access an index out of bounds in an array?
A) ArrayStoreException B) ArrayIndexOutOfBoundsException
C) NullPointerException D) IndexException

Q67. If you assign one array reference to another in Java:

int[] a = {1, 2, 3};

int[] b = a;

A) A copy of the array is made B) Both variables point to the same array
C) Compilation error D) A deep copy is performed

Q68. Which method from [Link] sorts an array in ascending order?


A) [Link]() B) [Link]() C) [Link]() D) [Link]()

Q69. Which method is used to search for a value in a sorted array?


A) [Link]() B) [Link]() C) [Link]() D) [Link]()

69. Which is a correct declaration of a two-dimensional array?


A) int[][] arr = new int[3][4]; B) int arr[][] = new int[3][];
C) int[][] arr = {{1,2},{3,4}}; D) All of the above

Q70. Which of these correctly declares a 3D array in Java?


A) int[][][] arr = new int[2][3][4]; B) int arr[2][3][4];

C) int arr[][][] = { { {1,2}, {3,4} } }; D) Both A and C

You might also like