0% found this document useful (0 votes)
8 views13 pages

MCQ's Java User-Defined Methods

This document contains a series of multiple-choice questions (MCQs) focused on user-defined methods in Java, covering topics such as method return types, parameter passing, method overloading, and access specifiers. Each question is accompanied by a reason explaining the correct answer. The content is structured into sections addressing basics, call mechanisms, overloading, and advanced concepts related to methods in Java.

Uploaded by

shikhar2207
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views13 pages

MCQ's Java User-Defined Methods

This document contains a series of multiple-choice questions (MCQs) focused on user-defined methods in Java, covering topics such as method return types, parameter passing, method overloading, and access specifiers. Each question is accompanied by a reason explaining the correct answer. The content is structured into sections addressing basics, call mechanisms, overloading, and advanced concepts related to methods in Java.

Uploaded by

shikhar2207
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

JAVA

TH
CLASS 10
USER-
DEFINED
METHODS

(MCQ’S)
Basics & Definitions (1–10)
1. The default return type of a user-defined
method in Java (if omitted) is:
A. float B. int C. void D. null
Reason: When no return type is explicitly
stated, Java assumes the method returns an
integer.

2. If two methods have identical signatures


(same name, same parameter types), the
compiler will report:
A. Runtime error B. Logical error C. Syntax
error D. No error
Reason: Having the same signature means
they’re considered the same method; Java
doesn't treat this as an overload error.

3. In calling int display(int a, char ch), which is


correct?
A. display('A', 45) B. display() C.
display(A,45) D. display(45,'A')
Reason: The argument types and order must
exactly match the method’s signature (int,
char).
4. What term is used for parameters listed in a method’s
definition?
A. actual B. formal C. reference D. class
Reason: These parameters are placeholders in the
method header; they're referred to as formal parameters.

5. What are the parameters used in a method call called?


A. actual B. formal C. reference D. class
Reason: These are real values passed during a method
call to match the formal parameters.

6. A method that does not return any value must have


return type:
A. int B. float C. void D. none
Reason: The void return type explicitly declares that the
method will not return any value.

7. A valid method prototype in Java is:


A. public perform(int a; int b) B. public perform(int a, int
b) C. public int perform(int a, int b) D. public perform
int(int a, int b)
Reason: The correct prototype includes return type,
method name, and comma-separated parameters.

8. Arrays in Java are passed to methods by:


A. reference B. value C. address D. none
Reason: Arrays are objects in Java, so they are passed by
reference, allowing changes to reflect in the original
array.
9. A method name in Java must begin with:
A. a letter B. a digit C. a symbol D. a space
Reason: Identifiers must start with a letter, underscore, or
dollar sign—not a digit or space.

10. Which keyword is used to return a value from a method?


A. send B. return C. break D. exit
Reason: The return statement sends a value back to the
method caller and exits the method body.
Call Mechanisms (11–20)
11. Copying values from actual to formal
parameters is called:
A. call by reference B. call by value C. call
by method D. call by argument
Reason: Primitive types are copied by value, so
changes inside the method don’t affect the
original.

12. When changing a parameter inside a


method affects the caller’s argument, it's:
A. call by reference B. call by value C.
none D. hybrid
Reason: Passing by reference allows the
method to modify the original argument.

13. A method is called impure if it:


A. pure B. impure C. perfect D. imperfect
Reason: It changes or has side-effects on
external data or state.
14. The advantage(s) of user-defined methods include:
A. reusability only B. complexity only C. reusability &
modularity D. complexity & modularity
Reason: They help break code into reusable, modular
segments.

15. When two methods have identical signatures, what


happens?
A. Runtime error B. Syntax error C. Logical error D. No
error
Reason: Identical signatures mean the methods are
considered the same; no overload conflict occurs.

16. Correct invocation of int display(int a, char ch) is:


A. display('A', 45) B. display() C. display(A,45) D.
display(45,'A')
Reason: The order and types (int followed by char) must
exactly match the method signature.

17. Static methods can access:


A. only static members B. non-static only C. both D.
none
Reason: Static methods belong to the class level and cannot
directly access instance members.

18. A method may have _____ return statements:


A. one B. two C. three D. any number
Reason: Multiple return statements are allowed, as long as
each returns the correct type.
19. Using * in an import statement includes:
A. one class B. current package C. all
classes in that package D. entire project
Reason: Wildcard import brings in all classes
inside the specified package.

20. The first line of a method that shows its


return type, name, and parameters is called:
A. header B. signature C. prototype D.
declaration
Reason: The signature uniquely identifies the
method by its name and parameter types.
Overloading & OOP Concepts (21–30)
21. The practice of defining multiple methods with
the same name but different parameters is:
A. overriding B. overloading C. encapsulation
D. inheritance
Reason: Overloading lets methods share names but
have different parameter lists.

22. Overloading demonstrates which OOP


principle?
A. inheritance B. polymorphism C.
abstraction D. encapsulation
Reason: The ability to use the same method name
with different behaviors is polymorphism.

23. What distinguishes overloaded methods?


A. return type B. parameter list C. access
modifier D. method body
Reason: Only differing parameter lists allow the
compiler to differentiate overloads.
24. If no access specifier is given, the method defaults
to:
A. private B. package-private C. public D. protected
Reason: Java uses package-private (default) visibility
when no specifier is present.

25. Static methods are also known as:


A. instance methods B. class methods C. object
methods D. package methods
Reason: Static methods belong to the class itself, not to
any particular object.

26. A method can accept how many parameters?


A. only one B. only two C. up to five D. any number
Reason: Java lets you define methods with any number
of parameters as needed.

27. Passing an array to a method uses which mechanism?


A. reference B. value C. address D. copy
Reason: Arrays are passed by reference, so
modifications in the method affect the original.

28. Variables declared inside a method are:


A. in global scope B. local to that method C. instance
variables D. shared variables
Reason: Local variables exist only within the method and
can't be used outside it.
29. Non-return methods (void) may contain a
bare return;:
A. false B. true C. both D. none
Reason: return; can be used to exit a void
method early without returning a value.

30. A valid call for int change(int p, int q) is:


A. r = change(10, 20); B. change(9.5, 6.7); C.
change(); D. none
Reason: The call must match the return type
and parameter types exactly.
Advanced & Specimen-Based (31–40)
31. The default visibility of a method without an
access specifier is:
A. protected B. package-private C. private D.
public
Reason: If no access level is declared, Java assigns
package-private by default.

32. A method that modifies its argument or external


data is called:
A. pure B. impure C. stable D. static
Reason: Impure methods cause side-effects by
changing data outside their scope.

33. The correct prototype of a method returning


float and taking two int parameters is:
A. public void show(int, int) B. public float
show(int, int) C. public float show(int) D. float
show()
Reason: Return type, method name, and full
parameter list must be specified clearly.
34. Primitive parameters are passed to methods using:
A. value B. reference C. address D. pointer
Reason: Java uses call-by-value for primitives; a copy is
sent to the method.

35. Built-in functions provided by Java are also known as:


A. library functions B. system functions C. machine
functions D. user functions
Reason: These are pre-written methods included in Java’s
standard libraries.

36. An alternative to return multiple values from a


method is:
A. arrays B. tuples C. integers D. void
Reason: Arrays can hold multiple values and be returned
as a single reference.

37. Declaring one method inside another is:


A. allowed always B. not allowed C. allowed if static
D. allowed for local methods
Reason: Java doesn't support nested method
declarations within other methods.

38. A method without an explicit return type will default


to:
A. void B. int C. float D. null
Reason: If not specified, Java assumes an int return type
by default.
39. Calling a method with mismatched
arguments results in:
A. runtime error B. compile error C. syntax
error D. logical error
Reason: Mismatched types or argument count
cause compile-time issues.

40. Two methods differing only in return type


will cause:
A. valid overload B. syntax error
C. compile error D. runtime error
Reason: The return type alone isn't enough to
distinguish overloaded methods.

END

You might also like