0% found this document useful (0 votes)
6 views

chapter user defined methods

The document consists of a series of questions and statements related to methods in programming, specifically focusing on return types, parameters, method invocation, and characteristics of methods. It includes multiple-choice questions, true/false statements, and open-ended questions about function prototypes and method visibility. Additionally, it addresses concepts such as method overloading, scope of variables, and the distinction between pure and impure functions.

Uploaded by

asitakumar25
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

chapter user defined methods

The document consists of a series of questions and statements related to methods in programming, specifically focusing on return types, parameters, method invocation, and characteristics of methods. It includes multiple-choice questions, true/false statements, and open-ended questions about function prototypes and method visibility. Additionally, it addresses concepts such as method overloading, scope of variables, and the distinction between pure and impure functions.

Uploaded by

asitakumar25
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1) A method that does not return a value has a ........... return type.

1. double
2. class
3. float
4. void

2) A method can return ...........

1. any number of values


2. 2 values
3. only 1 value
4. 3 values

3) If a method returns a value, then it must be ...........

1. of the same data type as defined in its prototype


2. void type
3. double type
4. boolean type

4) Parameters in the method definition are called ...........

1. actual parameters
2. formal parameters
3. informal parameters
4. void parameters

5) The parameters that are passed to the method when it is invoked are called ...........

1. formal parameters
2. actual parameters
3. informal parameters
4. void parameters

6) The method that changes the state of an object is known as ...........

1. pure method
2. impure method
3. perfect method
4. imperfect method

7) The scope of a local variable is limited to the ...........

1. Windows
2. Multiple programs
3. Class
4. Method or block it is declared in

8) The technique in which the change in the formal parameter gets reflected in the actual
parameter is known as ...........

1. call by reference
2. call by value
3. call by argument
4. call by method

9) In which technique are the values of actual parameters copied to the formal
parameters?

1. call by reference
2. call by value
3. call by argument
4. call by method

10) A method with many definitions is known as ...........

1. many method
2. multiple method
3. void method
4. overloaded method

State whether the given statements are True or False


11) A method may contain any number of return statements.

12) The non-static methods need an instance to be called.

13) A method can return more than one value.

14) Methods defined as void must return a value.

15) The static methods need an instance to be called.

16)In Java, all primitive types are passed by value and all reference types are passed by
reference.

17) You can place the return statement in a void method without any expression.
18)If a method returns a value, then it must be of the same data type as defined in the method
prototype.

19)Parameters in the method definition are called dummy parameters.

20) Methods reside in a class in Java.

21)Method overloading is one of the ways by which Java implements polymorphism.

22)The scope of a local variable is limited to the method or the block it is declared in.

23) The keyword static makes a method a class method.

24)An impure method always returns the same value when the same arguments are given.

25). The default return type of a User defined function is


Options
(a) float
(b) int
(c) void
(d) null
26) Function prototype means?
Options
(a) Return value of a function
(b) Name of the function
(c) Return type of the function
(d) Return type ,Name and Inputs to a function
//27) What is meant by private visibility of a method ?
28) What is the use of function overloading ?
29) What are the two ways of invoking functions?
30) Debug the errors and rewrite the following function prototypes:
(a) int sum(x,y);
(b) float product(a,int y);
(c) float operate(int x, float=3.4);
(d) float sum(int x,y);
31)Differentiate between pure and impure functions.
32) Differentiate between call by value and call by reference.

You might also like