X Practice Paper
X Practice Paper
Time: Reading time 15 minutes & Writing time 2 hours Marks: 100
Attempt all questions.
This paper is divided into two sections.
Attempt all questions from Section A and any four questions from Section B.
The intended marks for questions are given in brackets [ ].
This Paper consists of 7 pages.
ANSWER KEY
SECTION A
[Attempt all questions from this section]
Question 1 [20]
Choose the correct answers to the questions from the given options and write answers only.
iii) Java uses the term _____ to describe a collection of related classes:
a. library
b. package
c. folder
d. inheritance
iv) Which among the following is NOT a visibility mode used in the class?
a. private
b. protected
c. public
d. static
ix) A member variable declared with no access specifier has visibility only in the :-
a. class and subclass only
b. class and package only
c. class, package and subclass only
d. class only
x) The access specifier that gives most accessibility is___and the least accessibility is__: -
a. public and protected
b. default and private
c. public and private
d. private and protected
xii) If String str1=”great”; and String str2=”minds”; then what will be the output of
System.out.println(str1.substring(0,2).concat(str2.substring(1)));
a. gri
b. griminds
c. grem
d. grinds
xiii) which among the following is a valid statement to declare a double 2D array named arr of 3 rows
and 4 columns?
a. Double arr[] []= new double[3][4];
b. Double arr[] []= new arr[3][4];
c. Double arr[] []= new Double arr [3][4];
d. double arr[] []= new double[3][4];
In Java there is a member method of a class with no return type not even void is used to initialise the
instance variables. This member method can be default, parameterised or non-parameterised. Execution
of this method is must when the object of a class is created.
a. Both Assertion (A) and Reason(R) are true and reason(R) is a correct explanation of
Assertion(A).
b. Both Assertion (A) and Reason(R) are true but reason(R) is not a correct explanation of Assertion(A).
c. Both Assertion (A) is true and Reason(R) is false.
d. Both Assertion (A) is false and Reason(R) is true.
a. Both Assertion (A) and Reason(R) are true and reason(R) is a correct explanation of
Assertion(A).
b. Both Assertion (A) and Reason(R) are true but reason(R) is not a correct explanation of Assertion(A).
c. Both Assertion (A) is true and Reason(R) is false.
d. Both Assertion (A) is false and Reason(R) is true.
Question 2
(iv) Rohan has written the following program but there is an error while he tries to execute the code.
[2]
Name the error. How the program can be modified to get the correct answer?
class Example {
public static void main(String args[]) {
int a = 40, b = 60;
int Sum = a + b;
System.out.println( "Sum of variables is + sum); } } Sum and inverted comma missing compile
time error or syntax error
(v) The following program should print the largest of given three numbers. [2]
However, the code has errors. Fix the code so that it compiles and runs correctly.
int a = 2, b = 8, c = 6;
if (a > b | | a > c) // &&
System.out.println( a + " is the largest Number");
else if (b > a && b > c)
System.out.println(b + " is the smallest Number"); largest
else
System.out.println( c + " is the largest Number");
(ix) Write two point difference between static and non-static variables. [2]
Answer- Static variables are preceded by static keyword while non static variables are not.
They are called class variables and non static are called instance variables.
(x) Briefly define two ways of invoking functions. . [2]
Answer- 1) call by value- passing parameters to a method by value. 2) reference of actual parameter is
passed to the formal parameters.
SECTION B
(Answer any four questions from this section)
The answer in this section should consist of the programs in either BlueJ environment or
any program environment with Java as the base.
Each program should be written using variable description/ mnemonic codes so that the logic
of the program is clearly depicted.
Flow charts and algorithms are not required.
Question 3 [15]
Define a class called movieMagic with the following description:
Instance variable/Data member :
int year - To store the year of release of a movie
String title - To store the title of the movie
float rating - To store the popularity rating of the movie.
(minimum rating =0.0 and maximum=5.0)
Member Methods :
Void accept() – To input and store year, title and rating
void display() – To display the title of a movie and a message based on the rating as per the table given
below:-
System.out.println(title);
System.out.println(message);
}
Question 4 [15]
Write a program to accept a word and convert it into lowercase if it is in uppercase, and display the new
word by replacing only the vowels with the character following it.
Sample I/P- computer
O/P- cpmpvtfr
Answer-
import java.util.Scanner;
public class VowelReplace
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a word: ");
String str = in.nextLine();
str = str.toLowerCase();
String newStr = "";
int len = str.length();
Question 5 [15]
Write a program to fill 10 variables in a 1D array named list. Perform bubble sort and display the original
as well as sorted array in ascending order.
Sample Input- 65,47,40,9,37,72,45,17
Sample Output- 9,17,37,40,45,47,65,72
Answer:-
for(int i=0;i<len-1;i++)
{
for(int j=0;j<len-i-1;j++)
{ if(list[j] >list [j+1])
Int temp= list[j];
list[j]= list[j+1];
list[j+1]=temp; }}
Question 6 [15]
Design a class to overload a function as follows:
i) void compare(int ,int )- To compare two integer values and print the greater of the two integers.
ii) void compare( char,char)- To compare the numeric value of two characters with higher numeric
value.
iii) Void compare(String,String)- To compare the length of the two strings and print the longer of the
two.
Answer:-
public void compare(int a, int b) {
if (a > b) {
System.out.println(a);}
else {
System.out.println(b); }
if (x > y) {
System.out.println(a); }
else {
System.out.println(b); }}
else {
System.out.println(b);}
Question 7 [15]
Write a program to accept a number and check and display whether it is a perfect number or not. A
Number is said to be perfect if sum of all it’s factors(excluding the number itself) are equal to the
number.
Example- 496 Sum of Digits- 1+2+4+8+16+31+62+124+248 = 496
Answer-
import java.util.Scanner;
public class PerfectNumberExample1 {
public static void main(String args[]) {
long n, sum=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number: ");
n=sc.nextLong(); int i=1;
//executes until the condition becomes false
while(i <= n/2)
{ if(n % i == 0)
{
//calculates the sum of factors
Sum = sum + i; } //end of if
//after each iteration, increments the value of variable i by 1
i++; } //end of while
//compares sum with the number
if(sum==n) { //prints if sum and n are equal
System.out.println(n+" is a perfect number."); } //end of if else
//prints if sum and n are not equal
System.out.println(n+" is not a perfect number."); } }
Question 8 [15]
Write a program to perform binary search on a list of integers given below, to search for an element input
by the user. If it is found display the element along with its position, otherwise display the message
“Search element not found”.
5,7,9,11,15,20,30,45,89,97