0% found this document useful (0 votes)
41 views3 pages

Computer Dot Com: A Complete Computer Education Under W.B. Government Registered An ISO 9001: 2015 Certified Institute

The document discusses functions and methods in Java. It defines what a function prototype is, which is the first line of a function definition that specifies the return type and parameters. It also discusses function overloading as a way to implement polymorphism by defining functions with the same name but different parameters. Advantages of functions include managing complexity, hiding implementation details, and code reusability. The questions ask about function concepts like return types, parameters, recursive functions, and how polymorphism relates to overloading.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views3 pages

Computer Dot Com: A Complete Computer Education Under W.B. Government Registered An ISO 9001: 2015 Certified Institute

The document discusses functions and methods in Java. It defines what a function prototype is, which is the first line of a function definition that specifies the return type and parameters. It also discusses function overloading as a way to implement polymorphism by defining functions with the same name but different parameters. Advantages of functions include managing complexity, hiding implementation details, and code reusability. The questions ask about function concepts like return types, parameters, recursive functions, and how polymorphism relates to overloading.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Computer Dot Com

A complete computer education


Under W.B. Government registered
An ISO 9001: 2015 Certified Institute
Chapter- 3 [Function ]

1. A function can return only one value to its caller program.


2. If a function does not return any value its return type is void.
3. A function indicating the function name, return type along with function arguments is
known as function header/prototype.
4. The variables used to receive the values in function header are known as formal
parameters.
5. Method in a Java program resides in package.
6. The entire function body is enclosed under curly brackets.
7. The procedural function performs some actions without returning any output.
8. A function contains header and body.
9. Functions used with same name but different types of arguments are known as function
overloading.
10. A function that is called by itself in its body is known as recursive function.

Question 1

Define a function. What is meant by function prototype?

A function or a method is a sequence of statements grouped together and given a name.


This group of statements can be called at any point in the program using its name to
perform a specific task.
First line of function definition that tells about the type of value returned by the function
and the number and type of arguments is called function prototype.

Question 2

What are the two ways of invoking functions?

Two ways of invoking functions are:

1. Pass by value.
2. Pass by reference.

Question 3

What are the advantages of defining a method in a program?


Advantages of defining methods in a program are:

1. Methods help to manage the complexity of the program by dividing a bigger


complex task into smaller, easily understood tasks.
2. Methods are useful in hiding the implementation details.
3. Methods help with code reusability.

Question 4

What is meant by function overloading? In what way it is advantageous?

Function overloading is the process of defining functions/methods within a class, that have
the same name but differ in the number and/or the data types of their arguments.
Advantages of function overloading are:

1. Function overloading is one of the ways in which Java implements the object
oriented concept of Polymorphism.
2. With Function overloading, programmers don't have to create and remember
different names for functions doing the same thing for different data types.

Question 5

Define the following:

(a) Return data type

Return data type specifies the type of value that the method should return. It is mentioned
before the method name in the method prototype. It can be any valid primitive or
composite data type of Java. If no value is being returned, it should be void.

(b) Access specifier

Access specifiers determine the type of access to the method. It can be either public, private
or protected.

(c) Parameter list

Parameter list is a comma-separated list of variables of a method along with their


respective data types. The list is enclosed within a pair of parentheses. Parameter list can
be empty if the method doesn't accept any parameters when it is called.

(d) Recursive function

A function that calls itself inside its body is called a Recursive function.

(e) Method signature


Method signature comprises of the method name and the data types of the parameters. For
example, consider the below method:

int sum(int a, int b) {


int c = a + b;
return c;
}

Its method signature is:


sum(int, int)

Question 6

What is the role of the keyword void in declaring functions?

The keyword 'void' signifies that the function doesn't return a value to the calling function.

Question 7

If a function contains several return statements, how many of them will be executed?

A function can have multiple return statements but only one of them will be executed
because once a return statement is executed, the program control moves back to the caller
function skipping the remaining statements of the current function.

Question 8

Which OOP principle implements function overloading?

Polymorphism implements function overloading.

You might also like