Java Sample Questions 2
Java Sample Questions 2
Java Sample Questions 2
Fill-in-the-Blank Questions:
1. In Java, the process of creating a new object based on an existing class is called ___________.
Answer: instantiation
2. The Java keyword used to refer to the current instance of a class within its methods is ___________.
Answer: this
4. A Java method that has the same name as the class in which it is declared is called a ___________
method.
Answer: constructor
5. In Java, the process of converting an object of a subclass to its superclass type is called ___________.
Answer: upcasting
6. The Java keyword used to prevent a class from being instantiated is ___________.
Answer: abstract
8. The process of converting an object of a superclass to its subclass type is called ___________.
Answer: downcasting
9. In Java, a variable that is declared within a method and is accessible only within that method is called a
___________ variable.
Answer: local
10. The default value of a boolean variable in Java is ___________.
Answer: false
11. Java supports ___________ inheritance, meaning a subclass can inherit from only one superclass.
Answer: single
12. The Java keyword used to explicitly call the constructor of a superclass is ___________.
Answer: super
13. The Java keyword used to define a block of code that will be executed if a certain condition is true is
___________.
Answer: if
14. In Java, the process of removing an object's association with the garbage collector is called
___________.
Answer: dereferencing
15. A Java method that does not return any value is declared with the return type ___________.
Answer: void
16. The Java operator used to compare two primitive data types for equality is ___________.
Answer: ==
17. In Java, the process of converting a string into its numeric equivalent is called ___________.
Answer: parsing
18. A Java keyword used to declare a variable whose value cannot be changed is ___________.
Answer: final
19. Java's built-in mechanism for destroying objects that are no longer in use is called ___________.
Answer: garbage collection
20. The Java keyword used to exit a loop prematurely is ___________.
Answer: break
21. The process of hiding the implementation details of a class from the outside world is known as
___________.
Answer: encapsulation
22. In Java, the process of accessing variables and methods of a class without creating an object of that
class is called ___________.
Answer: static
23. The Java keyword used to define a collection of related methods with empty bodies is ___________.
Answer: interface
24. In Java, the process of defining multiple methods with the same name but different parameters is
called ___________.
Answer: method overloading
26. In Java, a statement that transfers control to another part of the program is called a ___________
statement.
Answer: control
28. In Java, a collection of characters enclosed within single quotes is called a ___________.
Answer: char literal
29. The Java keyword used to define a block of code that will be executed regardless of whether an
exception is thrown is ___________.
Answer: finally
30. The process of combining data and methods into a single unit is known as ___________.
Answer: encapsulation
31. In Java, a method that has the same name as another method in the same class but different parameters
is called a ___________ method.
Answer: overloaded
32. The Java keyword used to define a class member that belongs to the class rather than any specific
instance of the class is ___________.
Answer: static
33. In Java, a block of code that can catch and handle exceptions is enclosed within a ___________ block.
Answer: try-catch
34. The Java keyword used to prevent a method from being overridden in a subclass is ___________.
Answer: final
35. In Java, a collection of related methods and variables that can be used as a blueprint for creating
objects is called a ___________.
Answer: class
36. The Java operator used to compare two values and return true if they are not equal is ___________.
Answer: !=
37. In Java, a reserved word that has a special meaning and cannot be used as an identifier is called a
___________.
Answer: keyword
38. The process of converting a primitive data type into its corresponding wrapper class object is called
___________.
Answer: boxing
39. In Java, a reserved memory location that stores data is called a ___________.
Answer: variable
40. The method used to initialize an object in Java is called the ___________ method.
Answer: constructor
41. In Java, a reserved word used to declare a variable that cannot be changed after initialization is
___________.
Answer: final
42. The Java operator used to perform division and return the quotient is ___________.
Answer: /
43. In Java, a type of error that occurs during program execution and disrupts the normal flow of the
program is called a ___________.
Answer: runtime error
44. The Java keyword used to define a block of code that will be executed repeatedly as long as a
condition is true is ___________.
Answer: while
45. In Java, a reserved memory location that holds data of a specific type is called a ___________.
Answer: variable
46. The Java keyword used to define a block of code that will be executed if a certain condition is not true
is ___________.
Answer: else
47. In Java, a statement that transfers control to another part of the program is called a ___________
statement.
Answer: control
48. The Java operator used to perform multiplication is ___________.
Answer: *
49. In Java, a block of code that defines the behavior of an object is called a ___________.
Answer: method
50. The Java keyword used to define a block of code that will be executed repeatedly for each element in
a collection is ___________.
Answer: for
Multiple-Choice Questions:
6. Which keyword is used to declare a variable that does not hold any value?
a. empty
b. null
c. void
d. None of the above
Answer: d
9. Which keyword is used to define a method that can be accessed without creating an instance of the
class?
a. static
b. void
c. final
d. abstract
Answer: a
17. Which of the following is used to read input from the console in Java?
a. System.out.println()
b. System.in.read()
c. Scanner.nextLine()
d. BufferedReader.readLine()
Answer: d
20. Which keyword is used to define a method that cannot be implemented in the same class and must be
implemented in a subclass?
a. static
b. abstract
c. final
d. public
Answer: b
23. Which of the following is used to loop through the elements of an array in Java?
a. for loop
b. while loop
c. do-while loop
d. All of the above
Answer: d