In Java, functions are formally known as methods and serve as modular blocks of reusable code encapsulated within classes. A method definition specifies a return type, a unique name, and an optional parameter list governing input values. Java strictly uses pass-by-value semantics when evaluating parameters, meaning method arguments copy variable values rather than mutating original references directly. Understanding method signatures, overloading, overriding, and static versus instance scope is vital for writing clean, structured code and succeeding in technical programming exams.
Java Functions MCQs
1 min read
Correct Answer: b) To encapsulate a reusable block of code to perform a specific task
Explanation:
Methods modularize code by grouping related statements together, promoting code reuse and maintainability.
Correct Answer: c) Access modifier
Explanation:
Access modifiers (like public or private) are optional; default package-private visibility applies if omitted.
Correct Answer: b) It causes a compile-time error ('missing return statement').
Explanation:
Java enforces strict compile-time checking ensuring non-void methods guarantee a return path.
Correct Answer: b) Always by value
Explanation:
Java is strictly pass-by-value. For object variables, the value passed is a copy of the object's reference address.
Correct Answer: a) Defining multiple methods with the same name in the same class with different parameter lists
Explanation:
Method overloading is compile-time polymorphism achieved by varying parameter count, types, or order.
Correct Answer: a) void print(int... numbers)
Explanation:
Varargs syntax uses an ellipsis (...) after the data type, treating the parameter internally as an array within the method body.
Correct Answer: c) As the absolute last parameter
Explanation:
Java permits only one varargs parameter per method, and it must be positioned at the end of the parameter list.
Correct Answer: a) A method calling itself directly or indirectly to solve a problem
Explanation:
Recursion breaks complex problems down into smaller sub-problems by having a method invoke itself with a base case.
Correct Answer: b) StackOverflowError
Explanation:
Each recursive call pushes a new frame onto the thread's call stack; infinite recursion exhausts stack memory.
Correct Answer: b) No, because static context has no implicit this reference
Explanation:
Static methods belong to the class, not object instances, so they cannot directly access instance methods or variables.
Correct Answer: a) public static void main(String[] args)
Explanation:
The JVM specifically looks for a public, static, void method named main accepting a String array argument.
Correct Answer: b) Yes, you can define multiple overloaded versions of main, but the JVM will only execute the standard signature.
Explanation:
The main method can be overloaded like any other method, but entry-point launching strictly invokes String[] args.
Correct Answer: c) Nothing (it does not return a value)
Explanation:
The void keyword specifies that the method performs actions without returning a resultant value to the caller.
Correct Answer: b) Yes, an empty 'return;' statement can be used to exit the method early.
Explanation:
An empty return statement can terminate execution of a void method prematurely.
Correct Answer: a) Method name and parameter types (order and count)
Explanation:
In Java, a method signature consists strictly of the method name and its parameter list. Return types are not part of the signature.
Correct Answer: b) It causes a compile-time error ('method already defined').
Explanation:
Because return types are not part of the method signature, identical names and parameters result in duplicate method definitions.
Correct Answer: a) Defining a method in a subclass with the exact same signature as a method in its superclass to provide specific implementation
Explanation:
Method overriding enables runtime polymorphism by letting subclasses redefine inherited instance methods.
Correct Answer: b) No, static methods are hidden, not overridden, because resolution is determined at compile-time by reference type.
Explanation:
Static methods participate in method hiding rather than overriding.
Correct Answer: a) To declare checked exceptions that might be thrown during method execution, requiring callers to handle them
Explanation:
The throws keyword alerts callers that the method throws checked exceptions that must be handled or redeclared.
Correct Answer: b) Yes, unchecked exceptions are exempt from mandatory declaration or handling requirements.
Explanation:
Unchecked exceptions (subclasses of RuntimeException) do not require explicit throws declarations.
Correct Answer: a) An anonymous method passed as data, implementing a functional interface concisely
Explanation:
Lambda expressions provide functional programming syntax for single-method functional interfaces.
Correct Answer: a) A shorthand syntax for a lambda expression that executes an existing method
Explanation:
Method references (using `::`) make code cleaner when lambda bodies simply call an existing method.
Correct Answer: b) Yes, via default and static methods.
Explanation:
Java 8 introduced default and static methods in interfaces, allowing method bodies.
Correct Answer: a) A method declared without a body, ending with a semicolon, requiring subclasses to implement it
Explanation:
Abstract methods establish mandatory contracts for concrete subclasses.
Correct Answer: b) No, the final modifier prevents subclasses from overriding the method
Explanation:
Declaring a method as final locks its implementation across subclasses.
Correct Answer: a) Calling multiple methods sequentially on the same object in a single statement by returning 'this'
Explanation:
Method chaining relies on methods returning the current object reference (`return this`) to allow fluent syntax.
Correct Answer: a) The modifications affect the original object outside the method because the reference points to the same heap object.
Explanation:
Because Java passes object references by value (copy of the address), mutating object state inside a method reflects on the caller's object.
Correct Answer: b) No, because primitives are passed by value, meaning the method receives an independent copy.
Explanation:
Modifying a primitive parameter inside a method only alters the local copy; the caller's variable remains unchanged.
Correct Answer: a) A method implemented in platform-dependent code (like C or C++) using JNI (Java Native Interface)
Explanation:
Native methods use the `native` keyword to interface with low-level system libraries.
Correct Answer: a) A method whose execution is locked on the object instance (or class for static), allowing only one thread at a time
Explanation:
The synchronized keyword ensures thread safety by serializing thread access to method execution.
Correct Answer: a) When a subclass defines a static method with the same signature as a static method in its superclass
Explanation:
Static methods are hidden rather than overridden in subclasses.
Correct Answer: a) A synthetic method generated by the compiler during type erasure to support polymorphism with generics
Explanation:
Bridge methods ensure correct polymorphic method overriding when generic type parameters are erased.
Correct Answer: a) Yes, methods can return arrays of primitive or reference types.
Explanation:
Methods can return any valid array type by specifying the array notation (e.g., `int[]`) in the return type.
Correct Answer: a) No, Java methods cannot be returned directly, but methods can return functional interfaces or lambda expressions.
Explanation:
Java methods are not standalone first-class citizens, but lambda expressions and functional interfaces achieve similar factory behavior.
Correct Answer: a) Restricted exclusively to the method block from their point of declaration onward
Explanation:
Local variables have stack scope limited to the method execution context and are destroyed when the method returns.
Correct Answer: a) When compiler cannot determine which overloaded method to invoke due to ambiguous type widening conversions
Explanation:
Ambiguous method overloading causes a compile-time error when multiple overloads match argument types equally well.
Correct Answer: a) A method that enforces strict IEEE 754 floating-point calculations across all platforms
Explanation:
The strictfp modifier ensures floating-point calculations produce identical results across different hardware architectures.
Correct Answer: a) Yes, classes frequently provide multiple overloaded constructors to allow different ways of initializing object state.
Explanation:
Constructor overloading is a standard practice for supporting flexible object instantiation.
Correct Answer: a) Constructors have no return type whatsoever (not even void).
Explanation:
Declaring a return type on a constructor turns it into a regular method with the same name as the class.
Correct Answer: a) No, abstract methods must be overridden by subclasses, whereas final methods cannot be overridden.
Explanation:
Abstract and final are mutually exclusive modifiers; combining them causes a compile-time error.
Correct Answer: a) No, static methods belong to the class and cannot be overridden, whereas abstract methods require subclass overriding.
Explanation:
Abstract and static modifiers conflict conceptually and cannot be combined on a method.
Correct Answer: a) NullPointerException
Explanation:
Attempting to invoke an instance method on a reference pointing to null throws a NullPointerException at runtime.
Correct Answer: a) Yes, though it is discouraged and generally recommended to call them via the class name.
Explanation:
Java permits calling static methods via object references, though compilers evaluate them based on the reference type.
Correct Answer: a) A private or auxiliary method created to break down complex logic within a class into smaller, readable parts
Explanation:
Helper methods encapsulate internal support logic, keeping public methods clean and cohesive.
Correct Answer: a) Passing an interface reference or lambda to a method so it can notify the caller when an event occurs
Explanation:
Callbacks enable decoupled event-driven architecture and asynchronous communication.
Correct Answer: a) Yes, methods can accept any number of parameters of mixed primitive and reference types.
Explanation:
Method parameters can combine any valid Java types in any order.
Correct Answer: a) When a method parameter shares the name of an instance field, temporarily hiding the field within the method scope
Explanation:
Parameter shadowing requires using `this.field` to distinguish the instance variable from the parameter.
Correct Answer: a) A function that produces no side effects and always returns the same output given the same input parameters
Explanation:
Pure functions enhance predictability, testability, and concurrency safety.
Correct Answer: a) No, 'default' is not an access modifier keyword for methods (it is package-private by default; 'default' is used for interface methods).
Explanation:
Package-private visibility requires omitting access modifiers entirely; writing 'default' on a class method is a syntax error.
Correct Answer: a) A static method that creates and returns instances of a class, encapsulating object creation logic
Explanation:
Factory methods provide flexible alternatives to direct constructor instantiation.
Correct Answer: a) A public static method providing general-purpose helper tasks (e.g., Math.sqrt)
Explanation:
Utility methods are typically static and stateless, housed within utility classes.
Correct Answer: a) Yes, methods can accept 1D and multi-dimensional arrays as parameters.
Explanation:
Arrays are reference types and can be passed seamlessly into method parameter lists.
Correct Answer: a) The parameter value cannot be reassigned within the method body.
Explanation:
Declaring a parameter final prevents reassigning its reference or primitive value inside the method.
Correct Answer: a) The mechanism by which Java resolves overridden method calls at runtime based on the actual object type
Explanation:
Dynamic method dispatch underpins runtime polymorphism in Java.
Correct Answer: a) Yes, a method can declare checked exceptions in its throws clause even if code inside does not currently throw them.
Explanation:
Subclass implementations or interface contracts may throw declared exceptions, so declaring unused checked exceptions is permitted.
Correct Answer: a) A method featuring its own type parameter(s) declared before the return type (e.g., public T identity(T arg))
Explanation:
Generic methods introduce type safety and reusability across different data types.
Correct Answer: a) Yes, non-generic classes can define generic methods independently.
Explanation:
Generic methods can exist in any standard class by declaring their own type parameters.
Correct Answer: a) Allowing an overriding method in a subclass to return a subtype of the superclass method's return type
Explanation:
Covariant return types provide type-safe narrowing of return types during method overriding.
Correct Answer: a) When a class implements two interfaces containing default methods with identical signatures, requiring explicit override resolution
Explanation:
Diamond inheritance of default methods forces the implementing class to resolve ambiguity explicitly.
Correct Answer: a) No, the compiler generates an error if the method does not correctly override a parent method.
Explanation:
The @Override annotation enforces a compile-time check to prevent typo-based overriding bugs.
Correct Answer: a) Widening primitive conversions (e.g., int to long or float) when an exact parameter match is absent
Explanation:
If an exact overload match is missing, Java promotes smaller primitive types to wider types automatically.
Correct Answer: a) No, methods could not be passed as parameters without using object wrappers or anonymous inner classes.
Explanation:
Before Java 8 introduced lambdas, passing behavior required verbose anonymous inner classes implementing interfaces.
Correct Answer: a) They are created when the method is invoked and destroyed when the method execution completes.
Explanation:
Stack frame allocation ensures local variables exist exclusively during the method's active call duration.
Correct Answer: a) Yes, methods can contain multiple return statements branching across conditional blocks.
Explanation:
Methods can exit at different points using return statements based on conditional logic.
Correct Answer: a) The condition in a recursive method that stops further self-calls and initiates return unwinding
Explanation:
A base case is mandatory to prevent infinite recursion and StackOverflowError.
Correct Answer: a) Yes, provided any checked exceptions are declared in the throws clause or are unchecked RuntimeExceptions.
Explanation:
Exceptions propagate up the call stack if not caught locally, as long as method signature rules are satisfied.
Correct Answer: a) To pass computation results back to the calling code context
Explanation:
Return values provide the output data produced by method execution to the caller.
Correct Answer: a) Yes, because the static method has an explicit object reference to access instance members.
Explanation:
While static methods lack an implicit `this`, they can freely access instance members of explicitly passed object references.
Correct Answer: a) To test assumptions about program state during debugging, throwing AssertionError if false
Explanation:
Assertions validate internal assumptions during testing and debugging phases.
Correct Answer: a) No, return types alone cannot distinguish overloaded methods because ambiguous call sites cannot be resolved.
Explanation:
Java overload resolution relies on method name and arguments, ignoring return types.
Correct Answer: a) It locks on the Class object (Class.class), serializing access across all instances of that class
Explanation:
Static synchronized methods acquire a lock on the Class object rather than individual object instances.
Correct Answer: a) No, access modifiers are mutually exclusive; combining them causes a compile-time error.
Explanation:
A method can have only one access modifier (public, protected, private, or default).
Correct Answer: a) A public wrapper method that calls a private recursive method with extra accumulator or index parameters
Explanation:
Helper methods shield recursive implementation details and extra parameters from public API users.
Correct Answer: a) Yes, Java permits defining local inner classes within method bodies.
Explanation:
Local classes can be declared inside methods, with access to effectively final local variables.
Correct Answer: a) The exception propagates up the call stack to the calling method; if unhandled at top-level, the JVM prints the stack trace and terminates the thread.
Explanation:
Uncaught exceptions bubble up the call stack until handled or reaching the JVM uncaught exception handler.
Correct Answer: a) Yes, annotations (like @NonNull or @RequestParam) can be applied to method parameters.
Explanation:
Java supports annotations on local variables, fields, methods, parameters, and types.
Correct Answer: a) An optimization where the JIT compiler replaces a method call site with the actual body of the method to eliminate call overhead
Explanation:
Method inlining is a key JVM Just-In-Time optimization that boosts execution speed.
Correct Answer: a) Yes, mutual recursion occurs when method A calls method B, and method B calls method A.
Explanation:
Indirect or mutual recursion involves a cycle of method invocations achieving recursive problem solving.
Correct Answer: a) To specify the data type of the value the method will return to the caller
Explanation:
The return type informs the compiler and caller what type of data the method outputs.
Correct Answer: a) No, strictfp is a modifier that can accompany return types on methods and classes, but methods require a return type.
Explanation:
Methods always require a specified return type (or void), unlike constructors.
Correct Answer: a) Parameters are variable placeholders defined in the method signature; arguments are the actual values passed during method invocation.
Explanation:
Parameters are formal definitions in declarations, while arguments are actual values supplied when calling methods.
Correct Answer: a) Yes, methods can have empty parameter lists represented by empty parentheses '()'.
Explanation:
Parameterless methods are common for getter routines or action triggers.
Correct Answer: a) It causes a compile-time error because overriding methods cannot reduce accessibility.
Explanation:
Overriding rules state that visibility cannot be restricted below the access level of the superclass method.
Correct Answer: a) Yes, Java compiler scans the entire class, so method declaration order within a class does not matter.
Explanation:
Unlike some single-pass languages, Java's compiler processes entire class definitions regardless of method ordering.
Correct Answer: a) It stores local variables, parameters, return address, and intermediate computation states for that specific method call.
Explanation:
Each method invocation allocates a stack frame on the thread's call stack, which is popped upon method return.
Correct Answer: a) No, all traditional interface methods are implicitly abstract and cannot have a body unless marked default or static (or private in Java 9+).
Explanation:
Interface method bodies require explicit modifiers like default, static, or private.
Correct Answer: a) A helper method with a body inside an interface used to share code between default or other private interface methods
Explanation:
Java 9 introduced private interface methods to reduce code duplication among default methods.
Correct Answer: a) Yes, methods can return lambda expressions or method references matching a functional interface return type.
Explanation:
Methods can act as factories returning lambda expressions or method references.
Correct Answer: a) To provide intuitive method names for similar operations taking different argument types or counts
Explanation:
Overloading (like `println` taking int, String, double, etc.) improves API readability and usability.
Correct Answer: a) No, Java permits strictly one varargs parameter per method, and it must be the final parameter.
Explanation:
Allowing multiple varargs would create ambiguity in parameter matching during invocation.
Correct Answer: a) A new stack frame is pushed onto the thread's call stack, and execution control transfers to the called method.
Explanation:
Method invocation manages execution flow using stack frames.
Related Posts

Python Exception / Error Handling MCQs
Exception handling in Python provides a structured mechanism to catch, handle, and manage runtime errors without abruptly crashing an application.…
October 19, 2026By MCQs Generator

Java Exception Handling MCQs
Java exception handling is a powerful mechanism designed to manage runtime errors and maintain normal application flow. It relies on…
October 19, 2026By MCQs Generator

JavaScript Loops MCQs
Iteration structures in JavaScript allow developers to execute code blocks repeatedly based on dynamic boolean conditions. Standard loops such as…
October 19, 2026By MCQs Generator
Related Categories

AI & Data Science MCQ
5 topics
By MCQs Generator

Arts & Humanities MCQ
4 topics
By MCQs Generator

Civil Engineering MCQ
4 topics
By MCQs Generator

Commerce & Business MCQ
4 topics
By MCQs Generator

Competitive Exams MCQ
5 topics
By MCQs Generator

Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator

General Knowledge MCQ
2 topics
By MCQs Generator

General Science MCQ
4 topics
By MCQs Generator

Law & Judiciary MCQ
3 topics
By MCQs Generator

Mechanical Engineering MCQ
4 topics
By MCQs Generator

Medical & Health Sciences MCQ
4 topics
By MCQs Generator

Modern Tech Fields MCQ
3 topics
By MCQs Generator