






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Comprehensive Java Programming Exam Core Concepts & Object-Oriented Programming Target Audience: College & University Students โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
Question 1 (Core Syntax): Which of the following is the correct signature of the main method in a Java application? A) public void main(String args[]) B) public static void main(string[] args) C) public static void main(String[] args) D) public static void Main(String[] args) Question 2 (Java Keywords): What is the primary effect of using the final keyword on a variable in Java? A) The variable can be modified, but its value cannot be accessed by other classes. B) The variable's value must be evaluated at runtime and cannot be known at compile-time. C) The variable's value cannot be changed once it has been assigned. D) The variable can only be accessed within the same method. Question 3 (Data Types and Variables): What is the default value of an uninitialized int instance variable in Java? A) null B) 0 C) 1 D) It does not have a default value and will cause a compiler error. Question 4 (Object-Oriented Programming): Which of the following statements about an abstract class in Java is true? A) An abstract class cannot be instantiated directly. B) An abstract class must contain only abstract methods. C) A class that extends an abstract class must define all its methods as abstract. D) Variables in an abstract class can only be of type final.
Question 5 (Object-Oriented Programming): Which OOP principle allows a subclass to provide a specific implementation of a method that is already provided by its parent class? A) Encapsulation B) Abstraction C) Method Overriding D) Method Overloading Question 6 (Object-Oriented Programming): How is 'Encapsulation' primarily achieved in Java? A) By implementing interfaces. B) By allowing multiple classes to have the same method name. C) By declaring fields as private and providing public getter and setter methods. D) By making all methods static. Question 7 (Java Keywords): Which keyword is used in a subclass to call a constructor of its superclass? A) this B) super C) extends D) parent Question 8 (Object-Oriented Programming): What is the primary difference between Method Overloading and Method Overriding? A) Overloading happens at runtime, while Overriding happens at compile-time. B) Overriding involves methods with the same name but different parameters; Overloading requires identical signatures. C) Overloading occurs within the same class with different parameters, whereas Overriding occurs in subclass-superclass relationships with the same parameters. D) Overriding is used for primitives, while Overloading is used for objects. Question 9 (Arrays): Which of the following correctly declares and initializes an array of 5 integers in Java? A) int[] arr = {1, 2, 3, 4, 5, 6}; B) int[] arr = new int[5]; C) int arr = new int[5]; D) int arr() = new int[5];
Question 15 (Exception Handling): In Java, what is the difference between Checked and Unchecked exceptions? A) Checked exceptions occur at runtime, while Unchecked exceptions occur at compile-time. B) Unchecked exceptions must be caught using a try-catch block, or declared in a throws clause. C) Checked exceptions must be explicitly handled or declared at compile-time, whereas Unchecked exceptions do not have this requirement. D) Unchecked exceptions represent severe system failures that a program cannot recover from. Question 16 (Exception Handling): In a try-catch-finally block, when does the finally block execute? A) Only if an exception is thrown in the try block. B) Only if no exception is thrown in the try block. C) It always executes, regardless of whether an exception is thrown or caught. D) Only after the program terminates. Question 17 (Memory Management): Which of the following is stored in the Heap memory in Java? A) Local primitive variables B) Method references and parameters C) All objects and class instances D) Execution instructions Question 18 (Memory Management): What is the primary purpose of Garbage Collection in Java? A) To compile Java code into machine-level bytecode. B) To delete the source code files after a program runs. C) To clear the Stack memory of all local variables when a method returns. D) To automatically free up memory by destroying objects that are no longer reachable. Question 19 (Java Keywords): What does the static keyword indicate in Java? A) The variable can be modified, but its value cannot be accessed by other classes. B) The variable or method belongs to an instance of the class. C) The variable or method belongs to the class itself, rather than any specific instance.
D) The value of the variable is locked and cannot be changed. Question 20 (Java Keywords): What is the purpose of the this keyword in Java? A) To refer to the parent class. B) To declare a new class. C) To refer to the current object instance. D) To terminate the current program. Question 21 (Object-Oriented Programming): Which of the following best describes the concept of 'Polymorphism' in Java? A) The ability to restrict access to certain methods and data in a class. B) The capability of a class to derive properties and characteristics from another class. C) The ability of different objects to respond to the same method call in their own specific way. D) The process of hiding the implementation details and only showing the functionality. Question 22 (Exception Handling): Which of the following is an example of an Unchecked (Runtime) Exception in Java? A) IOException B) SQLException C) NullPointerException D) FileNotFoundException Question 23 (Core Syntax): What is the result of the modulo operator expression 10 % 3 in Java? A) 3 B) 0 C) 1 D) 3. Question 24 (Object-Oriented Programming): What was the primary difference between an Abstract Class and an Interface in Java (prior to Java 8)? A) An abstract class can have instance variables and concrete methods, whereas an interface can only have constants and abstract methods. B) Interfaces can be extended, but abstract classes cannot.
Question 1 Answer Key: Correct Option: C) public static void main(String[] args) Explanation: This is the exact signature the JVM looks for to start execution. It must be public so it's accessible, static so it can be called without an instance, void because it returns nothing, and use the lowercase 'main' name with a String array parameter. Question 2 Answer Key: Correct Option: C) The variable's value cannot be changed once it has been assigned. Explanation: A final variable acts as a constant if it is a primitive, or its reference cannot be updated to point to another object if it is a reference type. Question 3 Answer Key: Correct Option: B) 0 Explanation: In Java, all numeric primitive instance variables (like byte, short, int) are initialized to 0 by default. Local variables inside methods, however, do not get default values and cause compiler errors if uninitialized. Question 4 Answer Key: Correct Option: A) An abstract class cannot be instantiated directly. Explanation: You cannot create an object of an abstract class using the 'new' keyword. It must be extended by a concrete subclass that implements its abstract methods. Question 5 Answer Key: Correct Option: C) Method Overriding Explanation: Method overriding allows a child class to provide a distinct implementation for a method defined in its superclass, enabling runtime polymorphism. Question 6 Answer Key: Correct Option: C) By declaring fields as private and providing public getter and setter methods. Explanation: Encapsulation wraps data and code together into a single unit and restricts direct access to fields from outside classes to protect data integrity. Question 7 Answer Key: Correct Option: B) super Explanation: The 'super' keyword is explicitly used to reference parent class members
and invoke the parent class constructor. Question 8 Answer Key: Correct Option: C) Overloading occurs within the same class with different parameters, whereas Overriding occurs in subclass-superclass relationships with the same parameters. Explanation: Overloading resolves at compile-time using different signatures in the same class. Overriding resolves at runtime using the same signature across an inheritance hierarchy. Question 9 Answer Key: Correct Option: B) int[] arr = new int[5]; Explanation: This properly utilizes brackets to signify an array type and allocates memory for exactly 5 integer elements initialized to 0. Question 10 Answer Key: Correct Option: B) 11 Explanation: Java follows standard operator precedence (PEMDAS). Multiplication (*) has higher precedence than addition (+), so 3 * 2 runs first to equal 6, then 5 + 6 = 11. Question 11 Answer Key: Correct Option: C) String objects are immutable, meaning once created, their values cannot be modified. Explanation: String values cannot be changed after instantiation. Modifications create brand new String objects, allowing safe usage within Java's internal String Pool. Question 12 Answer Key: Correct Option: B) An ArrayList can dynamically resize itself, while a standard array has a fixed length. Explanation: Standard arrays are fixed in capacity upon instantiation. ArrayList resizes automatically when data is appended. Question 13 Answer Key: Correct Option: D) Map Explanation: HashMap maps unique keys to values, which is the foundational design definition of the java.util.Map interface.
Explanation: 'this' acts as an active execution pointer referencing the current specific object executing a method, clearing shadow parameter overlap ambiguity. Question 21 Answer Key: Correct Option: C) The ability of different objects to respond to the same method call in their own specific way. Explanation: Polymorphism captures dynamic dispatch capability where different specialized implementation variants run safely underneath abstract parent reference calls. Question 22 Answer Key: Correct Option: C) NullPointerException Explanation: NullPointerException inherits from RuntimeException, making it an unchecked variant produced via logic failures instead of external pipeline disruptions. Question 23 Answer Key: Correct Option: C) 1 Explanation: Modulo (%) extracts division remainders. 10 divided by 3 results in a quotient of 3 with a remaining remainder factor of 1. Question 24 Answer Key: Correct Option: A) An abstract class can have instance variables and concrete methods, whereas an interface can only have constants and abstract methods. Explanation: Interfaces were strictly pure structural blueprints before Java 8. Abstract classes can preserve continuous structural state variables alongside partial default coding patterns. Question 25 Answer Key: Correct Option: B) throw Explanation: The 'throw' keyword initiates an explicit execution interruption state manually inside functional bodies, whereas 'throws' declares execution risks in signatures.