Basic Java Programming Practice Exam
Section A: Multiple Choice Questions (2 marks each)
1. Which of the following is a valid way to declare an integer variable in Java?
• A. int number = 5;
• B. integer number = 5;
• C. num = 5;
• D. int = 5;
2. Which method is the entry point of a Java application?
• A. start()
• B. main()
• C. init()
• D. run()
3. Which keyword is used to create an object in Java?
• A. create
• B. new
• C. object
• D. make
4. Which of the following is a valid array declaration?
• A. int[] arr = new int[5];
• B. array arr = int[5];
• C. int arr = [5];
• D. int arr[] = int[5];
5. Which control statement is used to exit a loop prematurely?
• A. continue
• B. exit
• C. break
• D. return
6. Which of the following is NOT a primitive data type in Java?
• A. int
• B. boolean
• C. String
• D. double
7. Which class is used to handle dates and times in Java?
• A. DateTime
• B. Calendar
• C. LocalDate
• D. Time
8. Which keyword is used to inherit a class in Java?
• A. implements
• B. inherits
• C. extends
• D. super
9. Which of the following is true about abstract classes?
• A. They can be instantiated
• B. They must contain only abstract methods
• C. They can contain both abstract and concrete methods
• D. They cannot have constructors
10. Which interface is used to represent a predicate in Java?
• A. Function
• B. Predicate
• C. Consumer
• D. Supplier
Section B: True/False Questions (2 marks each)
1. Java supports multiple inheritance through classes. (True/False)
2. The main method in Java must be static. (True/False)
3. An interface can contain method implementations. (True/False)
4. The StringBuilder class is mutable. (True/False)
5. Java arrays are dynamically resizable. (True/False)
6. The 'this' keyword refers to the current object. (True/False)
7. Lambda expressions were introduced in Java 8. (True/False)
8. The default access modifier in Java is public. (True/False)
9. Java uses garbage collection for memory management. (True/False)
Section C: Matching Column Questions (4 marks each)
1. Match the following:
Column A:
• Class
• Interface
• ArrayList
• Exception
Column B:
• Blueprint for objects
• Collection that resizes dynamically
• Handles runtime errors
• Defines methods without implementation
2. Match the following:
Column A:
• Polymorphism
• Encapsulation
• Inheritance
• Abstraction
Column B:
• Hiding internal details
• Ability to take many forms
• Deriving new classes
• Focusing on essential features
Section D: Fill in the Blanks
1. Question 1:
In Java, a class is a blueprint for creating objects. To define a class, we use the ______
keyword. Each class can have ______, which are variables associated with the object. To
create an instance of a class, we use the ______ keyword followed by the class name. The
______ method is the entry point of any Java application.
Options:
class, fields, new, main, object, public, static, void
2. Question 2:
Arrays in Java are used to store multiple values of the same type. To declare an array, we
specify the type followed by ______. Arrays are ______ in size, meaning their length cannot be
changed once initialized. To access an element in an array, we use the ______ notation.
Multidimensional arrays are essentially arrays of ______.
Options:
square brackets, fixed, index, arrays, curly braces, dynamic, parentheses, objects