0% found this document useful (0 votes)
12 views15 pages

Java Programming Basics Quiz

The document contains a series of questions and answers related to Java programming concepts, covering topics such as keywords, data types, operators, control structures, and object-oriented principles. It includes questions about default values, method signatures, and the Java Virtual Machine (JVM). The content is structured in a quiz format, with each question followed by multiple-choice answers and the correct answer indicated.

Uploaded by

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

Java Programming Basics Quiz

The document contains a series of questions and answers related to Java programming concepts, covering topics such as keywords, data types, operators, control structures, and object-oriented principles. It includes questions about default values, method signatures, and the Java Virtual Machine (JVM). The content is structured in a quiz format, with each question followed by multiple-choice answers and the correct answer indicated.

Uploaded by

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

1. Which of the following is a valid keyword in Java?

A. then
B. goto
C. switch
D. loop
Ans: C

2. What is the default value of an int variable in Java?


A. 0
B. null
C. undefined
D. garbage
Ans: A

3. Which method is the entry point for any Java program?


A. main()
B. run()
C. start()
D. init()
Ans: A

4. Java was developed by:


A. Microsoft
B. Oracle
C. Sun Microsystems
D. IBM
Ans: C

5. Which of the following is not a Java primitive type?


A. byte
B. float
C. string
D. char
Ans: C

6. Which keyword is used to create a class in Java?


A. object
B. define
C. class
D. struct
Ans: C

7. Java code is compiled to:


A. Machine code
B. Bytecode
C. Object code
D. Assembly code
Ans: B
8. Which operator is used for comparison in Java?
A. =
B. :=
C. ==
D. !==
Ans: C

9. Which data type is used for true/false values?


A. int
B. binary
C. char
D. boolean
Ans: D

10. What does JVM stand for?


A. Java Visual Machine
B. Java Virtual Machine
C. Java Verified Machine
D. Java Variable Model
Ans: B

11. What will [Link]("Hello" + 5 + 6); print?


A. Hello56
B. Hello11
C. Hello 56
D. Compilation error
Ans: A

12. The keyword this refers to:


A. Current method
B. Current class
C. Current object
D. Superclass
Ans: C

13. Which of these is not a loop structure in Java?


A. for
B. repeat
C. while
D. do-while
Ans: B

14. Which access modifier makes members accessible only within the same class?
A. public
B. protected
C. default
D. private
Ans: D
15. Which keyword is used to inherit from a superclass?
A. implements
B. inherits
C. extends
D. super
Ans: C

16. Java supports:


A. Multiple inheritance using classes
B. Multiple inheritance using interfaces
C. Multiple inheritance using packages
D. No form of inheritance
Ans: B

17. A method that doesn’t return any value must have the return type:
A. int
B. null
C. void
D. empty
Ans: C

18. What is the size of int in Java?


A. 2 bytes
B. 4 bytes
C. 8 bytes
D. 1 byte
Ans: B

19. The break statement is used to:


A. Exit the program
B. Exit from a loop or switch
C. Skip current iteration
D. Break into debugger
Ans: B

20. Which loop is guaranteed to execute at least once?


A. for
B. while
C. do-while
D. All of the above
Ans: C

21. Which of these is not a valid identifier in Java?


A. my_var
B. 1variable
C. $temp
D. name1
Ans: B
22. Which keyword is used to create an object in Java?
A. class
B. alloc
C. malloc
D. new
Ans: D

23. What is the use of constructors?


A. Destroy objects
B. Allocate memory
C. Initialize objects
D. Declare variables
Ans: C

24. What is the output of:\[Link](4 + 1 + "A");


A. 5A
B. A5
C. 41A
D. Compilation error
Ans: A

25. Which statement is used to skip the current iteration in loops?


A. break
B. continue
C. skip
D. exit
Ans: B

26. Which of the following is not a type of constructor?


A. Default
B. Parameterized
C. Static
D. Copy
Ans: C

27. What does the return statement do in a method?


A. Terminates the program
B. Returns control to JVM
C. Returns a value and exits the method
D. Skips one iteration
Ans: C

28. In Java, == compares:


A. Values of primitives and references
B. Only values of primitive types
C. Content of objects
D. Memory locations of primitives
Ans: B
29. What is the output of [Link](2 + 3 * 4);?
A. 20
B. 14
C. 24
D. 18
Ans: B

30. Which of these cannot be used with switch statements?


A. byte
B. char
C. float
D. int
Ans: C

31. Which statement is true about Java?


A. Java is a compiled language only
B. Java is an interpreted language only
C. Java is both compiled and interpreted
D. Java is a scripting language
Ans: C

32. What will be the result of dividing an integer by zero?


A. Zero
B. Infinity
C. Runtime error
D. Compilation error
Ans: C

33. Which symbol is used for logical AND in Java?


A. &
B. &&
C. ||
D. and
Ans: B

34. Which is the correct syntax to declare an array of 5 integers?


A. int arr[5];
B. array int arr[5];
C. int[] arr = new int[5];
D. int arr[] = new int();
Ans: C

35. In Java, class names should be:


A. Capitalized
B. In lowercase
C. Start with a digit
D. Written with underscores
Ans: A
36. What is the output of [Link](true && false);?
A. true
B. false
C. 0
D. Error
Ans: B

37. Which of the following is used for single-line comments in Java?


A.
B. //
C. /**/
D. ;;
Ans: B

38. Java is platform-independent because:


A. It runs only on Windows
B. It uses machine code
C. It uses bytecode and JVM
D. It doesn’t need compilation
Ans: C

39. What is the result of 5 + 6 + "Java"?


A. Java11
B. 11Java
C. Java56
D. 56Java
Ans: B

40. Which of these is not a type of loop in Java?


A. for
B. do-while
C. foreach
D. repeat-until
Ans: D

41. What does the super keyword refer to?


A. Parent class
B. Current class
C. Child class
D. Interface
Ans: A

42. What is the size of char in Java?


A. 1 byte
B. 2 bytes
C. 4 bytes
D. 8 bytes
Ans: B
43. Which access specifier makes a member accessible in all classes?
A. protected
B. private
C. default
D. public
Ans: D

44. Java variables must be declared before:


A. Compilation
B. Execution
C. Use
D. Main method
Ans: C

45. Which keyword is used to stop a loop?


A. break
B. return
C. stop
D. next
Ans: A

46. What is the value of 10 % 3?


A. 3
B. 1
C. 0
D. 2
Ans: D

47. What is the output of [Link](1 + 2 + "Test");?


A. 3Test
B. Test12
C. 12Test
D. Test3
Ans: A

48. What is the default value of a boolean?


A. true
B. 1
C. 0
D. false
Ans: D

49. In Java, variables declared inside a method are called:


A. Instance variables
B. Static variables
C. Local variables
D. Global variables
Ans: C
50. What is the correct way to call a method in Java?
A. methodName;
B. methodName();
C. methodName[];
D. methodName = call;
Ans: B

51. Which of the following can be overloaded in Java?


A. Constructors only
B. Methods only
C. Both methods and constructors
D. Neither
Ans: C

52. The keyword this refers to:


A. Parent class object
B. Current object
C. New object
D. Static method
Ans: B

53. What is the output of [Link]('A' + 1);?


A. A1
B. B
C. 66
D. Error
Ans: C

54. Which of the following is a jump statement?


A. continue
B. for
C. switch
D. if
Ans: A

55. What is required to create an object in Java?


A. Constructor
B. Class
C. new keyword
D. All of the above
Ans: D

56. Which of the following loops always executes at least once?


A. for
B. while
C. do-while
D. none
Ans: C
57. What is the correct syntax to create a method in Java?
A. function myMethod()
B. def myMethod()
C. void myMethod()
D. create myMethod()
Ans: C

58. What is the range of byte data type?


A. -128 to 127
B. 0 to 255
C. -256 to 255
D. -128 to 255
Ans: A

59. Which of the following is not a Java keyword?


A. final
B. void
C. delete
D. break
Ans: C

60. What will be the output of [Link](10 > 5 && 2 < 1);?
A. true
B. false
C. Error
D. 1
Ans: B

61. When does a constructor get called?


A. After main()
B. Before class is loaded
C. At object creation
D. Never
Ans: C

62. Which of these is a valid identifier?


A. 1value
B. class
C. value_1
D. value-1
Ans: C

63. Which keyword is used to inherit a class?


A. implements
B. imports
C. extends
D. inherits
Ans: C
64. What is the default value of a String reference in Java?
A. ""
B. 0
C. null
D. undefined
Ans: C

65. Which of the following is used to convert a string to an integer?


A. [Link]()
B. [Link]()
C. [Link]()
D. [Link]()
Ans: C

66. What happens when you divide an integer by a floating-point number in Java?
A. Integer result
B. Float result
C. Error
D. Null
Ans: B

67. The break statement is used to:


A. Continue loop
B. Exit loop or switch
C. End method
D. Skip next iteration
Ans: B

68. A method that does not return any value must have return type:
A. null
B. int
C. void
D. empty
Ans: C

69. What is the index of the first element in an array?


A. 1
B. 0
C. -1
D. Depends on array
Ans: B

70. What is the correct file extension for a Java file?


A. .jav
B. .java
C. .jv
D. .class
Ans: B
71. Which is the correct way to declare a constant in Java?
A. const int x = 10;
B. int const x = 10;
C. final int x = 10;
D. constant int x = 10;
Ans: C

72. Which type of inheritance is supported in Java?


A. Multiple using classes
B. Single only
C. Multilevel and hierarchical
D. Hybrid using classes
Ans: C

73. Which is the entry point of any Java application?


A. start()
B. run()
C. main()
D. init()
Ans: C

74. What is the use of the new keyword in Java?


A. Declares a variable
B. Allocates memory
C. Terminates loop
D. Imports package
Ans: B

75. Java Virtual Machine (JVM) is:


A. A compiler
B. A browser
C. An interpreter
D. A memory unit
Ans: C

76. What does [Link]() do?


A. Prints error message
B. Reads input
C. Prints to console
D. Compiles code
Ans: C

77. Which data type would you use for storing true/false values?
A. int
B. byte
C. boolean
D. char
Ans: C
78. Which of these is used to create an infinite loop?
A. for(;;)
B. while(true)
C. do {} while(true)
D. All of the above
Ans: D

79. Which package is automatically imported in every Java program?


A. [Link]
B. [Link]
C. [Link]
D. [Link]
Ans: C

80. What is the default value of an int variable?


A. 0
B. null
C. undefined
D. garbage
Ans: A

81. Java follows which model of execution?


A. Write and Forget
B. Write Once, Compile Anywhere
C. Write Once, Run Anywhere
D. Write Often, Run Everywhere
Ans: C

82. Which of these keywords is used to define a class in Java?


A. Class
B. define
C. struct
D. class
Ans: D

83. Which of the following is a reference type?


A. int
B. float
C. double
D. String
Ans: D

84. Which operator is used to compare two values?


A. =
B. ==
C. :=
D. equals
Ans: B
85. The continue keyword is used to:
A. Exit a loop
B. Skip current iteration
C. Stop execution
D. Return from method
Ans: B

86. Which one is the correct method signature for main() in Java?
A. public static void main(String args[])
B. public static int main(String args[])
C. public void main(String[] args)
D. static void Main(String[] args)
Ans: A

87. How many primitive data types are there in Java?


A. 6
B. 8
C. 10
D. 12
Ans: B

88. What is the use of a constructor?


A. To destroy objects
B. To initialize objects
C. To create a class
D. To end a method
Ans: B

89. Which of these methods is called when an object is created?


A. finalize()
B. main()
C. constructor
D. destructor
Ans: C

90. Java uses which memory management system?


A. Manual memory management
B. Garbage collection
C. Reference counting
D. Static allocation
Ans: B

91. Which of these loops checks condition after executing statements?


A. while
B. for
C. do-while
D. foreach
Ans: C
92. Which is the correct way to start a multi-line comment in Java?
A. //
B. <!--
C. /**
D. /*
Ans: D

93. What is the default return type of a method if not defined?


A. int
B. void
C. Error
D. It must be defined
Ans: D

94. Which of the following keywords prevents inheritance?


A. private
B. static
C. final
D. abstract
Ans: C

95. What happens if we do not write a constructor in a class?


A. Program gives error
B. Default constructor is provided by compiler
C. Object cannot be created
D. Object is automatically garbage collected
Ans: B

96. What is a method?


A. Variable
B. Block of code that performs a task
C. Object
D. Keyword
Ans: B

97. Which keyword is used to define inheritance?


A. inherits
B. derive
C. extends
D. implement
Ans: C

98. Which operator is used to access members of an object?


A. ::
B. .
C. ->
D. #
Ans: B
99. Which part of Java makes it platform-independent?
A. JDK
B. JVM
C. Compiler
D. OS
Ans: B

100. Which of the following is a valid Java statement?


A. int num = 10;
B. int = 10;
C. num int = 10;
D. declare int num;
Ans: A

You might also like