SECTION A
(Attempt all questions.)
Question 1: Choose the correct answers to the questions from the given options. (Do not copy the the question, Write the correct answer only.)
i. Operators with higher precedence are evaluated before operators with relatively lower precedence. Arrange the operators given below in order of higher precedence to lower precedence.
Answer: a. Arithmetic, b. Relational, c. Logical Operator
ii. Which of the following keyword is used to create an instance of a class?
Answer: New Keyword
iii. What is the final value stored in variable x?
double a =-8.35;
double x = Math.abs(Math.floor(a));
Answer: 9
iv. Name the type of error in the statement given below:
int r=100/0;
Answer: Runtime
Question 2: Fill in the blanks with the correct option.
i. The ________ allows a class to use the properties and methods of another class.
ii. The number of bytes occupied by char data type is __________byte/s.
iii. The _________ is called an instance of a class.
iv. The _________ are the words that have special meanings.
v. Method that accepts a string without any space is ___________.
Question 3: Name the following:-
i. The keyword to make a variable as a class variable.
ii. Intermediate code obtained after compilation.
iii. The method with the same name as of the class and which does not have a return data type is called as.
iv. The statement to stop the execution of a construct.
v. Invoking a method by passing the objects of a class is termed as.
Question 4: State True Or False.
i. byte is a non-primitive data type.
ii. !(2>3&&4>6 )
iii. Scope of local variable is within a class.
iv. The default statement is optional in the switch- case.
v. The assignment operator(=) is left associative.
Question 5: Give the output of the following.
i. x + = x++ + ++ x + –x + x; [ x = 5 ]
Answer: 29
ii. if ( a > b )
System.out.println(a+b);
System.out.println (a*b); when a = 5 and b = 7.
Answer: 35
iii. String x = (a >= 90) ? “excellent” : “best”; when a = 90.
Answer: excellent
iv. switch ( x )
{ case ‘a’ : System.out.println(“Discipline”);
case ‘b’: System.out.println (“Dedication”); break;
case ‘c’: System. out.println(“Commitment”);
default: System. out.println(“Success”);
} when x=’A’
Answer: Success
v. n=1000;
while (n>10)
{n=n/10;
}
System.out.println(n); How many times the loop is executed and what is the output?
Answer: Loop is executed 2 times and the output is 10.
SECTION B
Question 7: Given below is a class with the following specifications:
Class name: overload
Member Methods:
void print ( int n ) – to print the first ‘n’ natural numbers
boolean print (int m, int n) – to check whether n is a multiple of m or not
Fill in the blanks of the given program with appropriate java statements –
class (a)_________
{
void print (int n)
{
int k;
for ( (b)_______; (c)_________; (d)________)
{
System.out.println(k);
}
}
boolean print( int m, (e)___________)
{
if ( (f)_______)
return true;
else
return false;
}
}
Answer:
a. overload
b. k=1
c. k<=n
d. k++
e. int n
f. if (n%m == 0)
Question 8: The following program is based on the specification given below. Fill in the blanks with appropriate java statements.
class name: telephone
member variables: int noc [ number of calls]
double bill [ telephone bill to be paid ]
String n [ name of the customer ]
Member methods :
- void input ( ) – to accept the data using the scanner class
- void print() – to print the details
- void calculate () – to calculate the telephone bill as per the following criteria based on the number of calls.
Number of calls | Rate per call |
First 100 calls | free |
Above 100 calls | Rs.2.50 |
- void main ( ) – to create an object of the class and invoke the functions of the class
class (a)_____
{
int noc; double bill ; String n;
Scanner ob = (b)__ ___Scanner(System.in);
void input( )
{ System.out.println(“Enter Number of calls”);
9
noc = (c)________;
System.out.println(“Enter name “);
n=ob.next();
}
void calculate()
{ if ( (d)______)
bill =0;
else
bill = (e)_________________;
}
void print()
{ System.out.println(“Name = “+n);
System.out.println(“Amount to be paid=”+bill);
}
void main ()
{ telephone t = new telephone();
t.input();
(f)__________;
t.print();
}
}
a. telephone
b. new
c. ob.nextInt()
d. noc < = 100
e. bill = noc*2.50
f. t.calculate()
Question 9: The following program segment calculates the norm of a number, norm of a number is square
the root of the sum of squares of all digits of the number.
Example:
The norm of 68 is 10
6×6 + 8×8 = 36+64 = 100 square root of 100 is 10.
Fill in the blanks with appropriate java statements.
void norm ( int n)
{ int d, s =(a)______; while ( (b)_____)
{ d = n%10;
s = (c)_______;
n=n/10;
}
System.out.println(“Norm = “ + (d)_______);
}
a. 0
b. n>0
c. s+d*d
d. Math.sqrt(s)
SECTION C
Question 10: Read the paragraph given below and answer the questions given below:
Case study 1
Decision control statements are used to check for conditions and execute the statements based
on the condition. The two decision control statements in java are if and switch, switch is also
called as multiple branching statements. An if statement within another if statement is termed
as Nested if Statement. The repetitive execution of a set of statements is termed as looping. The
two types of looping statements are entry controlled and exit controlled loops. Both while and
for are termed as entry-controlled loops. A for loop is used when the number of iterations is
known. A while is used when the set of statements is executed as long as the condition is true,
it is executed when the number of iterations is not known.
a. if and switch
b. Nested if
c. Looping
d. for(k=10;k<1;k++);