Section A
1. Give prototype of method isCorrect which receives a character ch and a integer n
and returns true or false
a. String isCorrect(char ch, integer n)
b. boolean isCorrect(char ch, integer n)
c. String isCorrect(char ch, int n)
d. boolean isCorrect(char ch, int n)
2. How does a function indicate it does not return any value?
a. By using void
b. By using null
c. By using none
d. By using no
3. What are the parameters in function call at line 1 called?
public class TestMax {
public static void main(String[] args) {
int m = max( 5 , 2 ); // Line 1
System.out.println(m);
}
/** Return the max between two numbers */
public static int max(int num1, int num2) { /* Implementation */ }
}
a. Variable Parameters
b. Reference Parameters
c. Formal Parameters
d. Actual Parameters
4. Which of the following is not passed by value?
a. double
b. array
c. boolean
d. byte
5. Identify what is the type of function max?
public class TestMax {
int highestNo;
public static int max(int n1, int n2) {
int x = 0;
if (n1 > n2)
highestNo = n1;
else
highestNo = n2;
return x;
}
}
a. Local Function
b. Global Function
c. Impure Function
d. pure Function
6 A constructor is used/called when a/an __________ is created
a. object
b. class
c. main
d. function
7 A constructor without any argument is known as _____________ constructor.
a. Parameterized
b. Copy
c. Instance
d. Non-parameterised
8 What is the output of the below Java program with many constructors?
public class test
{
test (int a)
{
System.out.println("Book=" + a);
}
test(float a)
{
System.out.println("Pen="+ a );
}
public static void main(String[] args)
{
test con = new test(50.5f);
}
}
a. Book=50
b. Pen=50.5
c. Compiler error
d. None of the above
Section B
1. Answer the questions based upon code below
static int solve(int a, Number num){
num.value*=a;
return num.value;}
i.
State the output of the following function call:
int c = solve (10, ob) if all member variables for this object ob are initialized to 0.
ii. Name the member variable as read in the method.
iii. What is expected data type of this member variable?
iv. Name the reference data type and the primitive data types as read from the
function definition.
2. Read the given program and answer the questions below.
void doSum(int x, double y);
void doSum (double x, double y);
(i)
Write the java statement to invoke the method “doSum” using actual parameters, a
= 2, b = 4.
(ii) Write the java prototype to overload the method doSum to return a double result
and accepts three double parameters.
3. What is the difference between call by value and call by reference?
4. What is the difference between formal and actual parameters?
5. What is the difference between function and constructor?
Section C
1.
Write a java class Taxi with following details
Instance Variables
int kms
int amt
char rain (Y or N)
String name
Instance Methods
Taxi() - Default constructor to initialize all values
void Input() – Function to input name, sex and kms.
void Calculate() Function to calculate amt based upon criteria below. Add Rs 100 surcharge
if it is raining.
void Display() – Display the bill in following format
NAME KMS RAIN AMOUNT
Xx xx xx xx
Write main() to create the object and call the functions as necessary.
2.
Check if a number is 'Twisted Prime', A number is called Twisted prime, if it is a prime
number and the new number obtained after reversing the digits is also a prime number. Write
a program to accept a number and check whether the number is 'Twisted Prime' or not.
Sample Input: 167
Sample Output: 761
167 is a 'Twisted Prime'.