Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Revision Worksheet - User Defined Functions

The document consists of a revision worksheet focused on user-defined functions in Java, covering various concepts such as function prototypes, access specifiers, method overloading, and differences between local and global variables. It includes specific questions that require defining functions, explaining keywords, and providing examples related to Java programming. Additionally, it addresses class design and the implementation of methods within classes.
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)
9 views3 pages

Revision Worksheet - User Defined Functions

The document consists of a revision worksheet focused on user-defined functions in Java, covering various concepts such as function prototypes, access specifiers, method overloading, and differences between local and global variables. It includes specific questions that require defining functions, explaining keywords, and providing examples related to Java programming. Additionally, it addresses class design and the implementation of methods within classes.
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/ 3

Revision Worksheet, (User defined Functions)

Q1. Write the function prototype for the function “sum” that takes an integer variable (x) as its argument and
returns a values of float data type.
Q2. What is the use of keyword this?
Q3. Name the keyword that causes the control to transfer back to the method call.
Q4.When there are multiple definitions with the same function name, what makes them different from each
other?
Q5. Consider the following code and answer the question that follows:
class Academic
{
int x,y;
void access()
{
int a,b;
Academic student = new Academic( );
System.out.println(“Object created”);
}
}
(i) What is the object name of class Academic?
(ii) Name the class variables used in the program.
(iii) Name the local variables used in the program.
(iv) Give the type of function used and its name.

Q6. Consider the following class:


public class Myclass
{
public static it x=3,y=4;
public int a=2, b=3;
}
(i) Name the variables for which each object of the class will have its own distinct copy.
(ii) Name the variables that are common to all objects of the class.
Q7. Write the prototype of a function check which takes an integer as an argument and returns a character.
Q8. Differentiate between formal parameter and actual parameters.
Q9. Write function prototype for function PosChar which takes a String argument and a Character argument and
return an integer value.
Q10. Name any two access specifiers.
Q11. What does the following mean?
Employee staff = new Employee();
Q12. Name the keyword which :
(i) indicates that a method has no return type.
(ii) makes the function as a class method.
Q13. State a difference between call by value and call by reference.
Q14. Write a java statement to create an object mp4 of class Digital.
Q15. What are the two ways of invoking functions?
Q16. Explain the concept of functions overloading with example.
Q17. Give the prototype of a function search which receives a sentence sentnc and a word wrd and returns true
or false?
Q18. Differentiate between pass by value and pass by reference.
Q19. What is the purpose of new operator?
Q20. What is a pure function? How is it different from an impure function?
Q21. Explain the function of a return statement.
Q22. Differentiate between static and non static functions.
Q23. Give the prototype of a function check which receives a character ch and integer n and returns true or false.
Q24. Define : Overloaded method , with an example.
Q25. Give the prototype of a function which receives a sentence, a character and and integer value and return a
boolean value.
Q26. Differentiate between a local variable and a global variable. Give examples also.
Q27. What is the following called?
(i) First line of a function
(ii) Total number and types of parameters a function contains.
Q28. Give two reasons why do we need function overloading in java.
Q29. Write the prototype of the function modify that takes a String and a character type variable as arguments
and returns true or false.
Q30. Define polymorphism. How is it implemented in java?
Q31. What does void return type signify?
Q32. Write the function prototype of function “compute” that takes an integer variable “m” as its argument and
return a value of float data type.
Q33. What is a method signature? Give example also.
Q34. Write three advantages of creating functions in java programs.
Q35. What are access specifiers in java? Name three access specifiers.
Q36. Explain the meaning and use of public , private and protected keywords in functions.
Q37. Define a class as follows:
Class name : Mobile
Data members : compname – to store company name
type- to store ‘B’ for basic phone, ‘S’ for smart phone
price – to store the price
discount- to store the discount amount
Methods : 1. Void readInfo() – to company name, mobile type and price.
2. void calc( ) – to modify the price as price = price – discount where discount is 10%
of price if price is less than Rs.5000, 20% if price is Rs. 5000/- or above but
less than Rs. 10000/- and 30% if price is Rs. 10,000/- or above
3. void display( ) – To print all the details as company name, type, price discount.
Write main() method to create object of the class to call the above member functions .

Q38. Design a class to overload a function area() as follows:


(i) double area(double a, double b, double c) with three double arguments, returns the area of a scalene triangle
using the formula :
area = 𝑠(𝑠 − 𝑎)(𝑠 − 𝑏)(𝑠 − 𝑐)
Where s = 𝑎+𝑏+𝑐
2

(ii) double area(int a, int b, int height) with three integer arguments, returns the area of a trapezium using the
formula: area = 12 height(a+b)
(iii) double area(double diagonal1, double diagonal2) with two double arguments, returns the area of a rhombus
using the formula: area = 12 (diagonal1 x diagonal2)

You might also like