Class10 QuestionBank HalfYearly
Class10 QuestionBank HalfYearly
Chapter-Introduction to OOP
b) A java program developed and executed by the users without using web
browser
is known as:
i. object
ii. application
iii. applet
iv. byte code
Page 1 of 19
2. Answer the following questions.
a) Name four basic principles of OOP.
b) How Data Encapsulation and Data Abstraction are interrelated in OOP?
c) State any four features of Java.
d) State any two advantages of OOP.
Page 2 of 19
iii) main
iv) class
b) Size of double data type is
i) 4 bytes
ii) 1 byte
iii) 2 bytes
iv) 8 bytes
Page 3 of 19
Operators in Java
Page 4 of 19
a=x*y;
}
3. Write a menu driven program in java to accept a choice and perform the
following operations as given below.
Choice 1: Input the three sides of a triangle and check whether it forms a
triangle or not. If it forms a triangle, check whether it is an equilateral,
isosceles or a scalene triangle.
(Hint: To form a triangle, each side should be less the sum of the other two `
sides.
To form an equilateral triangle every side should be equal.
To form an isosceles triangle any two sides should be equal.
To form a scalene triangle all three sides should be different from each other.)
Inputs in Java
Page 5 of 19
e) Identify the type of error in following statement to calculate the average of
three numbers (a, b & c) :-
double average = a + b +c/3;
i) Syntax Error
ii) Logical Error
iii) Runtime Error
iv) No Error
i) int
ii) float
iii)double
iv) All
b) Which of the following syntax is true to find the square root of a number?
i) sqrt(a)
ii) Math.sqrt(a)
iii) Squareroot(a)
iv) None
i) Math
ii) Scanner
iii) Maths
iv) Calc
i) -9.99
ii) 9.99
iii) 0.99
iv) None
Page 6 of 19
e) Give the output of Math.sqrt(x); when x = 9.0
i) 3
ii) 3.0
iii) 3.00
iv) all
3. Write a program in Java to input three numbers and display the greatest and
the smallest of the two numbers using Mathematical Library functions only.
Conditional Statements
1. Choose the correct answer.
a)Which of the following is multi-branching statement in JAVA?
a. if
b. else
c. switch
d. for
Page 8 of 19
Programs
Q1. Central Library charges late fine for book submission as per the following:
Write a Java program to accept the total number of late days. Calculate and
display the total late fine to be paid by the borrower.
Q2. The table below shows the rate of income tax for an Employee:
Write a program in Java to accept the name and taxable income of a person.
Calculate and display the income tax payable along with the name of the person.
Q3. Write a program to input three angles of a triangle and check whether
a triangle is possible or not. If possible then check whether it is an acute-angled
triangle, right-angled or an obtuse-angled triangle otherwise, display 'Triangle not
possible'.
Sample Input: Enter three angles: 40, 50, 90
Sample Output: Right Angled Triangle
Page 9 of 19
Q4. Write a menu driven JAVA program using switch case only to perform the
following:
If user chooses 1 then accept a number and check whether it’s a prime number or
not. (A number is prime if it is divisible only by 1 and itself)
If user chooses 2 then accept a number and find the sum of its digits.
Eg: If number is 123 then output should be 1+2+3 = 6
For any other choice display “Incorrect Input”.
i) break
ii) void
iii) continue
iv) return
i) Infinite loop
ii) Delay loop
iii) Bodyless loop
iv) Null loop
c. To execute a loop for 10 times, which of the following statement will be used.
i) for(int i=6;i<=26;i=i+2);
ii) for(int i=3;i<=30;i=i+3);
iii) for(int i=0;i<10;i=i+1);
iv) All of the above
i) for
ii) while
iii) do while
iv) do
Page 10 of 19
b) Analyze the following program segment and determine how many times
the loop will be executed and what will be the output of the program
segment.
int k=1, i=2;
while (++i<6)
k*=i;
System.out.println(k);
c) State the difference between entry controlled loop and exit controlled
loop.
d) Analyze the given program segment and answer the following questions:
for(int i=3;i<=4;i++)
{
for(int j=2;j<i;j++)
{
System.out.print(“Hello ”);
}
System.out.printlin(“WIN”);
}
i. How many times does the inner loop execute ?
ii. Write the output of the program segment.
3. Write a program to print the first 15 numbers of the Pell series. Pell
series is such a series which starts from 1 and 2 , and subsequent
numbers is the sum of twice the previous number and the number
previous to the previous number. Pell series: 1, 2, 5, 12, 29, 70, 169,
408, 985, 2378, 5741, 13860, …
4. Write a program to input two integers and check whether it forms an
amicable pair or not. An amicable pair is such that, the sum of the
factors excluding itself of one number is the other number and sum
of the factors excluding itself of the other number is this number.
Example, (220, 284). Since sum of factors
excluding itself of : 220=
1+2+4+5+10+11+20+22+ 44+55+110=284
284= 1+ 2+4+71+142=220.
Page 11 of 19
Class as the Basis of all Computation
1. Choose the correct answer.
a) The access specifier which prohibits a class member from being used outside a
class is ____________
i) Private
ii) Public
iii) Protected
iv) Default
b) A static method is also called a ____________
i) Instance method
ii) Class method
iii) Defined method
iv) Fixed method
c) Code reuse is implemented by __________
i) Abstraction
ii) Inheritance
iii) Polymorphism
iv) Function overloading
d) ___________ keyword is used to provide access to classes stored inside a package in
our program.
i) import
ii) this
iii) private
iv) final
b) Write differences between User-defined data type and Primitive data type.
c) Differentiate between public and private modifiers for the members of a class.
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
void print(): to print the details as follows:
Page 12 of 19
Name of the customer: …………………….
Number of units consumed : ……………………
Bill amount : ……………………………
Write a main method to crate an object of the class and call the above member
methods.
Chapter-Library Classes:
Question 1
Choose the correct options:
a) Which of the following is not an OOP concept?
i. encapsulation
ii. polymorphism
iii. exception
iv. abstraction
b) What are the return type and type of argument of the isWhiteSpace( )
method?
i. char, char
ii. char, boolean
iii. boolean, char
iv. Boolean, (no argument)
Question 2
a) State the output of the following program snippet:
int n=97;
char ch= Character.toUpperCase((char)n);
System.out.println(ch + “Great Victory”);
Page 13 of 19
b) Give output of the following code:
Question 3
Write a program to input two characters. Find the difference (d) between
their ASCII
codes. Display the following messages along with difference:
If d=0 : Both the characters are same.
If d<0 : First character is smaller.
If d>0 : Second character is smaller.
Sample Input :D
P
Sample Output : d=68-80= - 12
First character is smaller.
Question 4
Write a program to input a character, check whether it is an alphabet or not,
if the character is an alphabet, then change to its opposite case, otherwise
print “Not an alphabet.”
Sample Input 1 : A Sample Input 2 : 5
Sample Output 1 : a Sample Output 2 : “Not an
alphabet”
Question 5
Write a program to input a letter. Find its ASCII code. Reverse the ASCII code and
display the equivalent character.
Page 14 of 19
Sample Input :Y
Sample Output : ASCII code = 89
Reverse the code = 98
Equivalent character: b
Function/Methods
a) What is the return type of a method that does not return any value?
i) int
ii) float
ii) void
iv) double
b) What is the process of defining more than one method in a class differentiated
by method signature?
i) Function overriding
ii) Function overloading
iii) Function doubling
iv) None of the mentioned
Page 15 of 19
c) Public access method “increment” which accepts an object of Myclass
type as parameter and does not return any value.
d) Protected access method largest which accepts a float type, int type and
double type data as parameters and have a byte type as return type.
e) Public access static method calculate which accepts a byte and int type
data type as parameters and return float type.
Page 16 of 19
d) Create a class with the following methods:
a. int sum(int n), which finds the sum of the digits in n and returns it.
b. void call() to input an integer using scanner and find the sum of its
digits using the above
method.
e) Create a class with the following methods:
a. int sum(int n), which finds the sum of the digits in n and returns it.
b. void call() to input 10 integers using scanner and find the sum of its
digits of each integer value entered by the user using the above
method.
Arrays
c) What will be the first index and the last index for an array int X[10]:
i) 1 , 10
ii) 1, 11
iii) 0, 9
iv) 0,10
a. If a[ ] = { 1,5,8,3,10};
iii) What is the value of a.length?
iv) What is the value of a[4] * a[4-4]?
c. What value will be stored in the array after execution of the following code ;-
d. If a[]={11,22,33,44,55} then what vales are stored in the array after execution
of the following code :-
for(int i =a.length-1;i>0;i--)
a[--i]= a[i]+10;
Page 18 of 19
e. int arr[ ][ ]={{12,-7,54},{11,23,-9},{18,5,5}};
i) How much memory will be occupied by the matrix arr[ ][ ] ?
ii) What will be the output of the following statement?
System.out.print(arr[0][0]+arr[2][0]+arr[0][2]+arr[2][2])
3. WAP to store values in an array. Display the original array. Arrange the
elements in descending order of their values using Selection Sort technique.
4. WAP to store values in a matrix. Display the original matrix. Also display sum
of all the elements of the given matrix.
5. WAP to store values in a character array. Find the lower case alphabets
present in the array along with their ASCII values in a tabular format. Also
display numbers of all the lower case alphabets.
6. WAP to store values in a single dimensional integer array. Display the highest
and the second highest elements from the given array.
7. Write a program to store names of ten cricketers and name of the countries
they play for in two different string arrays. accept the name of a cricketer and
search his/her name in the array using Binary Search technique. If found
display the corresponding country name otherwise display suitable message.
8. WAP to store values in a square matrix of size NxN. Display the original matrix.
Replace all the diagonal elements (both right and left) with zero. Display the
modified matrix.
9. WAP to store values in a double array. Find the average/mean value of all the
elements. Display the mean value also display the difference of each element
from the mean value.
10. WAP to store vales in a 2D array. Display the original array. Find the
sum of the elements in each column.
******************
Page 19 of 19