A method that does not return a value has a ........... return type.
- (a)boolean
- (b)class
- (c)int
- (d)void ✓
ICSE Class 9 Computer Applications · Solutions for Class 9 ICSE Logix Kips Computer Applications with BlueJ Java · 23 solved questions
A method that does not return a value has a ........... return type.
A method can return ...........
If a method returns a value, then it must be ...........
Parameters in the method definition are called ...........
The parameters that are passed to the method when it is invoked are called ...........
The scope of a local variable is limited to the ...........
A method can return more than one value.
False
Solution not available in the source paper.
Methods defined as void must return a value.
False
Solution not available in the source paper.
A method may contain any number of return statements.
True
Solution not available in the source paper.
The non-static methods need an instance to be called.
True
Solution not available in the source paper.
The static methods need an instance to be called.
False
Solution not available in the source paper.
If a method returns a value, then it must be of the same data type as defined in the method prototype.
True
Solution not available in the source paper.
Parameters in the method definition are called dummy parameters.
True
Solution not available in the source paper.
Methods reside in a class in Java.
True
Solution not available in the source paper.
The scope of a local variable is limited to the method or the block it is declared in.
True
Solution not available in the source paper.
The keyword static makes a variable a class variable.
True
Solution not available in the source paper.
What is a method? Explain the various parts of a method.
A method is a named block of code within a class. It executes a defined set of instructions when called from another part of the program. The different parts of the method are access-modifier, type, method-name, parameter-list and method-body.
How do you define and invoke a method?
The syntax of a method definition is:
[access-modifier] type method-name (parameter-list)
{
method-body;
}
To invoke a method, write the name of the method and specify the value of arguments of its parameter list. Below example shows the definition and invocation of a method:
public class DisplayMessageDemo {
public void DisplayMessage() {
System.out.println("Hello World!");
}
public void MyMessage() {
DisplayMessage();
}
}Explain the role of return statement in a method?
Return statement sends back the value given to it from the called method to the caller method. It also transfers the program control back to the caller method from the called method.
What does void signify in the method prototype?
void in method prototype means that the method does not return any value.
Explain the difference between actual and formal parameters with one example of each.
The parameters that appear in the method definition are called formal or dummy parameters whereas the parameters that appear in the method call are called actual parameters. Example:
public class FindSquareDemo {
public int FindSquare(int x) {
int result;
result = x * x;
return result;
}
public void MyFindSquare() {
int num = 4;
int myResult;
myResult = FindSquare(num);
System.out.println("Square of " + num + " is " + myResult);
}
}
Here, variable x in the definition of FindSquare is formal parameter and variable num in the method call of FindSquare is actual parameter.
Explain static and non-static methods.
Static methods are created with static keyword in their method prototype as shown below:
public static return-type method-name(parameter-list)
{
Method-body
}
Static methods can be called directly using class name but they can't access instance variables and non-static methods of the class.
The non-static methods are created without the static keyword in their method prototype as shown below:
public return-type method-name(parameter-list)
{
Method-body
}
An instance of the class is required to call non-static methods.
Explain the scope of variables in Java
Scope of the variable determines in which parts of the program the variable is accessible. It is of the following types:
Press ↓ to reveal a solution and move to the next question. Back to Solutions for Class 9 ICSE Logix Kips Computer Applications with BlueJ Java.