Quick Review Flashcards - Click to flip and test your knowledge!
Question
In Java programming, what is a 'method'?
Answer
A set of statements that can perform a specific task and be used multiple times.
Question
How do methods help in 'reducing complexity' of code?
Answer
They divide a complex problem into smaller, manageable parts that can be called when required.
Question
The ability to define a method once and call it repeatedly anywhere in a program is known as code _____.
Answer
reusability
Question
Why are methods often compared to 'black boxes'?
Answer
The user only needs to know what inputs to pass and what output to expect, without knowing the internal logic.
Question
What happens if a defined method is never called in the program?
Answer
It will never be executed.
Question
What are the two primary parts of a method definition?
Answer
The header (prototype) and the body.
Question
Which method component determines the type of access (e.g., public, private) to the function?
Answer
Access specifier
Question
In a method header, which keyword is used if the method does not return any value?
Answer
void
Question
What is the function of 'parameters' in a method definition?
Answer
They allow the method to receive data (arguments) when it is called.
Question
The block of statements executed when a method is called is surrounded by which symbols?
Answer
Curly braces $\{ \}$
Question
According to Java naming conventions, what part of speech should a method name typically be?
Answer
A verb
Question
In multi-word method names like 'readInfo', what is the casing convention for the first letter of the second word?
Answer
Upper case
Question
What is the definition of a 'method prototype'?
Answer
The first line of a method that tells the compiler the number and type of parameters and the return type.
Question
How does the 'method signature' differ from the 'method prototype'?
Answer
The signature refers specifically to the list of parameters along with their data types.
Question
What is 'method invocation'?
Answer
The process of calling a defined method for execution.
Question
Static methods are also known as _____ methods.
Answer
Class
Question
How can a static method be invoked directly within its own class?
Answer
By using just the name of the method followed by parentheses.
Question
What must be created before a non-static method can be invoked?
Answer
An instance (object) of the class.
Question
Non-static methods are also commonly referred to as _____ methods.
Answer
Instance
Question
Which operator is used to call a non-static method through an object reference?
Answer
The dot (.) operator
Question
What is the difference between 'Actual Parameters' and 'Formal Parameters'?
Answer
Actual parameters appear in the method call, while formal parameters appear in the method definition.
Question
In what order are values from actual parameters passed to formal parameters?
Answer
Sequentially from left to right.
Question
What is the 'lifetime' of a formal parameter?
Answer
It only exists until the method executes once completely.
Question
In 'Call by Value', what is copied to the formal parameters?
Answer
A copy of the value of the actual parameters.
Question
How does a change to a formal parameter in 'Call by Value' affect the actual parameter?
Answer
It has no effect on the actual parameter.
Question
What type of data is typically passed using the 'Call by Value' mechanism?
Answer
Primitive data types
Question
In 'Call by Reference', what information about the variable is passed to the method?
Answer
The memory location (reference) of the original variable.
Question
How does a change to a formal parameter in 'Call by Reference' affect the actual parameter?
Answer
The change is automatically reflected in the actual parameter because they share the same memory location.
Question
Which data types require the 'Call by Reference' mechanism?
Answer
Object or array variables
Question
Which keyword is used to send a value back to the calling method?
Answer
return
Question
How many values can a Java method return at a time?
Answer
Exactly one
Question
What happens to method execution immediately after a 'return' statement is encountered?
Answer
The method terminates and control returns to the caller.
Question
What defines a 'Pure Method' (Accessor Method)?
Answer
A method that returns a value based on arguments without changing the state of an object.
Question
What defines an 'Impure Method' (Mutator Method)?
Answer
A method that causes a change in the state of an object, such as modifying instance variables.
Question
What is 'Method Overloading'?
Answer
The ability to have multiple methods with the same name but different signatures within the same class.
Question
What specific part of a method must be different for overloading to be valid?
Answer
The parameter types or the number of parameters (the signature).
Question
Under which type of polymorphism is method overloading categorised?
Answer
Static polymorphism (or early binding).
Question
If two methods have the same name and parameter list but different return types, are they considered overloaded?
Answer
No, they must have different signatures.
Question
What is the purpose of using suffixes like 'L' in values like '25423L' during method calls?
Answer
To differentiate between data types (e.g., long vs int) to help the compiler select the correct overloaded method.
Question
The first line of a method that tells the compiler about the method's name, return type, and parameters is called the _____.
Answer
header
Question
Variables defined within a method or block that are only accessible within that block are _____ variables.
Answer
local
Question
Which modifier is used to define a method that belongs to the class itself rather than a specific object?
Answer
static
Question
A method used only to retrieve or calculate a value without altering any class data is a/an _____ function.
Answer
Accessor (or Pure)
Question
What is the mathematical formula for a 'Factorion' (Special Number) as described in the source material?
Answer
A natural number that equals the sum of the factorials of its digits.
Question
An 'Automorphic Number' is defined as a number whose _____ ends in the same digits as the number itself.
Answer
square
Question
A 'BUZZ number' is any number that is either divisible by $7$ or ends with which digit?
Answer
$7$
Question
A 'Pronic number' is defined as the product of two _____ integers.
Answer
consecutive
Question
In Java, what is considered the basis of all computation?
Answer
The class
Question
Which Java library class contains pre-defined methods like 'sqrt()' and 'pow()'?
Answer
The Math class
Question
What error message is displayed if a method call does not match its prototype?
Answer
Compile-time error (or parameters are not proper).
Question
If a method is defined as 'private int findCube(int x)', what is its signature?
Answer
(int x)
Question
What is the return type of the method call 'Math.pow(2, 3)'?
Answer
double
Question
What is the next action taken by the program after a method call completes its execution?
Answer
Control returns to the statement immediately following the method call.
Question
In the method header 'public static void main(String args[])', which part is the exception list?
Answer
It is not present (it is optional).
Question
In the example 'double x = Math.sqrt(y)', what is 'y' in relation to the method call?
Answer
The argument (or actual parameter).