1. Java is a __________ programming language.
a) Machine level
b) Assembly level
c) High-level
d) Low-level
Answer: c) High-level
2. Which of the following is a feature of Java?
a) Platform dependent
b) Object-oriented
c) Pointer support
d) Multiple inheritance through classes
Answer: b) Object-oriented
3. Java follows the principle of:
a) Write Once, Run Anywhere
b) Write Anywhere, Run Once
c) Compile Everywhere
d) Run Once, Write Anywhere
Answer: a) Write Once, Run Anywhere
4. Which method is the entry point of a Java program?
a) start()
b) run()
c) main()
d) init()
Answer: c) main()
5. Which keyword is used to define a class in Java?
a) define
b) class
c) Class
d) new
Answer: b) class
6. Which of the following is NOT a Java token?
a) Keywords
b) Identifiers
c) Variables
d) Operators
Answer: c) Variables
7. Which symbol is used to end a statement in Java?
a) :
b) ;
c) .
d) ,
Answer: b) ;
8. Which keyword is used to declare a constant in Java?
a) const
b) constant
c) final
d) static
Answer: c) final
9. Which data type is used to store a single character?
a) String
b) char
c) character
d) byte
Answer: b) char
10. The size of int in Java is:
a) 2 bytes
b) 4 bytes
c) 8 bytes
d) 1 byte
Answer: b) 4 bytes
11. Which data type is used for true/false values?
a) bool
b) boolean
c) bit
d) logical
Answer: b) boolean
12. Which primitive type stores decimal values?
a) int
b) char
c) float
d) boolean
Answer: c) float
13. The size of byte in Java is:
a) 1 byte
b) 2 bytes
c) 4 bytes
d) 8 bytes
Answer: a) 1 byte
14. Which of the following is the largest integer type in Java?
a) int
b) short
c) long
d) byte
Answer: c) long
15. Conversion of smaller type to larger type is called:
a) Narrowing
b) Casting
c) Widening
d) Boxing
Answer: c) Widening
16. Conversion of larger type to smaller type is called:
a) Widening
b) Narrowing
c) Promotion
d) Auto casting
Answer: b) Narrowing
17. Which operator is used for addition?
a) *
b) +
c) /
d) %
Answer: b) +
18. Which operator is used to compare equality?
a) =
b) ==
c) !=
d) >=
Answer: b) ==
19. Which operator is used for logical AND?
a) &
b) &&
c) ||
d) !
Answer: b) &&
20. Which operator is used for assignment?
a) ==
b) =
c) !=
d) +=
Answer: b) =
21. Which operator increases a value by 1?
a) --
b) ++
c) +=
d) %
Answer: b) ++
22. Which operator is called the ternary operator?
a) ? :
b) ::
c) <>
d) &&
Answer: a) ? :
23. Bitwise operators work on:
a) Decimal values
b) Boolean values
c) Binary bits
d) Characters
Answer: c) Binary bits
24. Which operator is used for remainder?
a) /
b) %
c) *
d) -
Answer: b) %
25. Which of the following is a relational operator?
a) &&
b) ||
c) >=
d) ++
Answer: c) >=
1. A class in Java is a __________.
a) Real-world object
b) Blueprint for creating objects
c) Method
d) Variable
Answer: b) Blueprint for creating objects
2. Which keyword is used to define a class in Java?
a) object
b) class
c) define
d) new
Answer: b) class
3. Which of the following is the correct syntax to declare a class?
a) myClass Student { }
b) class Student { }
c) Student class { }
d) define class Student { }
Answer: b) class Student { }
4. Variables and methods inside a class are called:
a) Tokens
b) Members
c) Packages
d) Operators
Answer: b) Members
5. A variable declared inside a class but outside methods is called:
a) Local variable
b) Instance variable
c) Static block
d) Temporary variable
Answer: b) Instance variable
6. Which of the following is used to perform actions in a class?
a) Variables
b) Methods
c) Objects
d) Packages
Answer: b) Methods
7. A constructor is mainly used for:
a) Destroying objects
b) Initializing objects
c) Printing output
d) Creating packages
Answer: b) Initializing objects
8. Constructor name must be the same as:
a) Method name
b) Package name
c) Class name
d) Variable name
Answer: c) Class name
9. Constructors do not have:
a) Name
b) Parameters
c) Return type
d) Access modifier
Answer: c) Return type
10. Which constructor has no parameters?
a) Parameterized constructor
b) Default constructor
c) Copy constructor
d) Static constructor
Answer: b) Default constructor
11. Which access specifier allows access only within the same class?
a) public
b) protected
c) private
d) default
Answer: c) private
12. Which access specifier allows access from anywhere?
a) private
b) public
c) protected
d) default
Answer: b) public
13. Which access specifier allows access within the same package?
a) default
b) private
c) final
d) static
Answer: a) default
14. Which keyword is used for class-level members shared by all objects?
a) final
b) static
c) public
d) this
Answer: b) static
15. Static members belong to:
a) Object
b) Method
c) Class
d) Constructor
Answer: c) Class
16. Which keyword is used to access current object reference?
a) super
b) static
c) this
d) final
Answer: c) this
17. Which method is automatically called when an object is created?
a) main()
b) constructor
c) finalize()
d) display()
Answer: b) constructor
18. A class inside another class is called:
a) Parent class
b) Child class
c) Nested class
d) Super class
Answer: c) Nested class
19. Which of the following is NOT a class member?
a) Variables
b) Methods
c) Constructors
d) Loop statements
Answer: d) Loop statements
20. How many public classes can be present in one Java file?
a) One
b) Two
c) Unlimited
d) Three
Answer: a) One
21. Which symbol is used to access class members?
a) ;
b) ,
c) .
d) :
Answer: c) .
22. Which keyword is used to create an object?
a) class
b) new
c) this
d) static
Answer: b) new
23. Which of the following is true about methods?
a) They store data
b) They define behavior
c) They define packages
d) They create arrays
Answer: b) They define behavior
24. Constructor overloading means:
a) Same constructor repeated
b) Multiple constructors with different parameters
c) Deleting constructors
d) Using static constructor
Answer: b) Multiple constructors with different parameters
25. Nested classes help in:
a) Improving readability and grouping related code
b) Deleting methods
c) Increasing errors
d) Avoiding objects
Answer: a) Improving readability and grouping related code
.3 Objects
1. An object in Java is an instance of a __________.
a) Method
b) Class
c) Package
d) Constructor
Answer: b) Class
2. Which keyword is used to create an object?
a) class
b) static
c) new
d) this
Answer: c) new
3. Memory for an object is allocated using:
a) create
b) new
c) class
d) import
Answer: b) new
4. Which of the following is correct for object creation?
a) Student();
b) Student s = new Student();
c) new Student;
d) object Student();
Answer: b) Student s = new Student();
5. The variable that stores the address of an object is called:
a) Instance variable
b) Object reference
c) Static variable
d) Local variable
Answer: b) Object reference
6. Which operator is used to access members of an object?
a) :
b) ;
c) .
d) ,
Answer: c) .
7. A method is called using:
a) Object name + dot operator
b) Constructor
c) Package
d) Array
Answer: a) Object name + dot operator
8. Constructor is invoked when:
a) Method is called
b) Object is created
c) Package is imported
d) Program ends
Answer: b) Object is created
9. Which method is used before an object is destroyed (older concept)?
a) delete()
b) finalize()
c) remove()
d) clear()
Answer: b) finalize()
10. Automatic memory cleanup in Java is done by:
a) Compiler
b) JVM
c) Garbage Collector
d) Constructor
Answer: c) Garbage Collector
11. Garbage collection removes:
a) Active objects
b) Unused objects
c) Variables
d) Methods
Answer: b) Unused objects
12. Which of the following best describes object lifecycle?
a) Declaration → Method → End
b) Creation → Usage → Destruction
c) Class → Package → Import
d) Constructor → Package → Exit
Answer: b) Creation → Usage → Destruction
1.4 Arrays
13. An array is used to store:
a) Different data types only
b) Multiple values of same type
c) Only strings
d) Only objects
Answer: b) Multiple values of same type
14. Array indexing in Java starts from:
a) 1
b) -1
c) 0
d) 2
Answer: c) 0
15. Which is the correct way to declare an array?
a) int arr;
b) int[] arr;
c) array int arr;
d) arr int[];
Answer: b) int[] arr;
16. Which keyword is used to allocate memory for an array?
a) array
b) create
c) new
d) class
Answer: c) new
17. Which of the following creates a one-dimensional array?
a) int arr[][];
b) int[] arr = new int[5];
c) int arr;
d) int arr[][][];
Answer: b) int[] arr = new int[5];
18. A two-dimensional array is also called:
a) Single array
b) Matrix
c) Object array
d) Command array
Answer: b) Matrix
19. Which syntax is used for a two-dimensional array?
a) int[] arr;
b) int[][] arr;
c) int arr;
d) int[][][] arr;
Answer: b) int[][] arr;
20. Multidimensional arrays are:
a) Arrays with more than one dimension
b) Arrays with only one row
c) Arrays with only one column
d) Arrays without size
Answer: a) Arrays with more than one dimension
21. Accessing all elements one by one is called:
a) Initialization
b) Traversing
c) Allocation
d) Compilation
Answer: b) Traversing
22. Which loop is commonly used to traverse arrays?
a) if
b) switch
c) for
d) break
Answer: c) for
23. An array of objects stores:
a) Primitive values
b) References of objects
c) Methods
d) Constructors
Answer: b) References of objects
24. Command line arguments are stored in:
a) int[]
b) String[] args
c) char[]
d) Object[]
Answer: b) String[] args
25. Which method gives the length of an array?
a) size()
b) length
c) count()
d) getSize()
Answer: b) length
2.1 Inheritance
1. Inheritance in Java is used for:
a) Hiding data
b) Reusing code
c) Deleting objects
d) Creating arrays
Answer: b) Reusing code
2. Which keyword is used for inheritance in Java?
a) implement
b) inherits
c) extends
d) super
Answer: c) extends
3. When one class inherits another single class, it is called:
a) Multilevel inheritance
b) Single inheritance
c) Hierarchical inheritance
d) Multiple inheritance
Answer: b) Single inheritance
4. When a class inherits from a derived class, it is called:
a) Hierarchical inheritance
b) Multiple inheritance
c) Multilevel inheritance
d) Hybrid inheritance
Answer: c) Multilevel inheritance
5. When many classes inherit one parent class, it is called:
a) Hierarchical inheritance
b) Single inheritance
c) Multilevel inheritance
d) Multiple inheritance
Answer: a) Hierarchical inheritance
6. Which keyword is used to refer to parent class members?
a) this
b) final
c) super
d) static
Answer: c) super
7. Method overriding means:
a) Same method name with different parameters
b) Redefining parent class method in child class
c) Creating constructor
d) Hiding variables
Answer: b) Redefining parent class method in child class
8. Which keyword prevents method overriding?
a) static
b) final
c) private
d) super
Answer: b) final
9. Runtime polymorphism is achieved using:
a) Constructor overloading
b) Method overriding
c) Static methods
d) Packages
Answer: b) Method overriding
10. Java does not support multiple inheritance using:
a) Classes
b) Interfaces
c) Packages
d) Objects
Answer: a) Classes
2.2 Interfaces
11. An interface in Java is used for:
a) Complete abstraction
b) File handling
c) Array creation
d) Garbage collection
Answer: a) Complete abstraction
12. Which keyword is used to define an interface?
a) class
b) interface
c) abstract
d) extends
Answer: b) interface
13. Which keyword is used to implement an interface?
a) extends
b) implement
c) implements
d) interface
Answer: c) implements
14. A class can implement:
a) Only one interface
b) Multiple interfaces
c) No interface
d) Only two interfaces
Answer: b) Multiple interfaces
15. Which inheritance is supported through interfaces?
a) Single inheritance
b) Multiple inheritance
c) Hierarchical inheritance
d) Multilevel inheritance
Answer: b) Multiple inheritance
16. An interface can extend:
a) Class
b) Another interface
c) Method
d) Object only
Answer: b) Another interface
17. A marker interface contains:
a) Variables only
b) Methods only
c) No methods or fields
d) Constructors
Answer: c) No methods or fields
18. Example of marker interface is:
a) Runnable
b) Serializable
c) Thread
d) File
Answer: b) Serializable
2.3 Files and Streams
19. File handling in Java is used for:
a) Data storage
b) Printing output only
c) Creating classes
d) Creating arrays
Answer: a) Data storage
20. Which class is used to work with files?
a) FileReader
b) File
c) Reader
d) Scanner
Answer: b) File
21. Byte stream is used for:
a) Text data only
b) Binary data
c) Integer values only
d) Strings only
Answer: b) Binary data
22. Character stream is used for:
a) Binary data
b) Text data
c) Boolean values
d) Objects only
Answer: b) Text data
23. Which class is used to read bytes from a file?
a) FileWriter
b) FileReader
c) FileInputStream
d) BufferedWriter
Answer: c) FileInputStream
24. Which class is used to write characters to a file?
a) FileWriter
b) FileInputStream
c) OutputStream
d) File
Answer: a) FileWriter
25. BufferedReader is mainly used for:
a) Fast reading of text
b) Creating objects
c) Array handling
d) Exception handling
Answer: a) Fast reading of text
2.4 Exception Handling
26. An exception is:
a) Normal program flow
b) Runtime error
c) Variable declaration
d) Method call
Answer: b) Runtime error
27. Which block is used to handle exceptions?
a) if
b) try
c) switch
d) loop
Answer: b) try
28. Which block catches the exception?
a) final
b) throw
c) catch
d) throws
Answer: c) catch
29. Which block always executes whether exception occurs or not?
a) throw
b) finally
c) catch
d) class
Answer: b) finally
30. Checked exceptions are checked at:
a) Runtime
b) Compile time
c) Execution end
d) Garbage collection
Answer: b) Compile time
31. Unchecked exceptions occur at:
a) Compile time
b) Runtime
c) Design time
d) Load time
Answer: b) Runtime
32. Which keyword is used to explicitly throw an exception?
a) throws
b) catch
c) throw
d) final
Answer: c) throw
33. Which keyword is used to declare exceptions?
a) throw
b) throws
c) final
d) super
Answer: b) throws
34. User-defined exceptions are called:
a) Checked exceptions
b) Custom exceptions
c) Runtime exceptions
d) Final exceptions
Answer: b) Custom exceptions
35. Passing exception from one method to another is called:
a) Exception handling
b) Exception propagation
c) Exception checking
d) Exception throwing
Answer: b) Exception propagation