,,,,
,,,,
CLASS IX (2024-25)
Chapter 1: Introduction to Object Oriented Programming Concepts – Assignment 1
(a) Encapsulation
(b) Polymorphism
(c) Exception
(d) Abstraction
(a) Abstraction
(b) Encapsulation
(c) Polymorphism
(d) Inheritance
(iii). Which among the following feature is not in the general definition of OOPS?
(a) Modularity
(b) Efficient Code
(c) Code reusability
(d) Duplicate or Redundant Data
(iv). Which feature of OOPS derives the class from another class?
(a) Inheritance
(b) Data hiding
(c) Encapsulation
(d) Polymorphism
(a) Only 1
(b) Only 999
(c) Only 100
(d) Any number
(a) technique of combining more than one member functions into a single unit.
(b) mechanism of combining more than one data member into a single unit.
(c) mechanism of combining more than one data members and member functions that implement on
those data members into a single unit
(d) technique of combining more than one data members and member functions into a single unit,
which can manipulate any data.
(ix). Which among the following feature does not come under the concept of OOPS?
(x). Which of the following definition best describes the concept of polymorphism?
(a) It is the ability to process the many messages and data in one way
(b) It is the ability to process the undefined messages or data in at least one way
(c) It is the ability to process the message or data in more than one form
(d) It is the ability to process the message or data in only one form
(xiv). An object belonging to a particular class is known as a/an _________________ of that class.
(a) Interface
(b) Instance
(c) Alias
(d) Member
(xv). Objects that share the same attributes and behavior are grouped together into a/an
_________________
(a) Interface
(b) Instance
(c) Alias
(d) Class
(xvi). ______________ refers to the act of representing essential features without including the background
details.
(a) Abstraction
(b) Inheritance
(c) Encapsulation
(d) Polymorphism
(xvii). _________________ is the feature by means of which one class acquires the properties of another
class.
(a) Abstraction
(b) Inheritance
(c) Encapsulation
(d) Polymorphism
(xviii). The ability of a function or object to take on multiple forms is called ________________
(a) Abstraction
(b) Inheritance
(c) Encapsulation
(d) Polymorphism
(d) Wrapping up data and related functions in a single unit represents encapsulation.
(f) The class that is derived from another class is called a superclass.
(i) A class is a blueprint for the attributes and behaviors of a group of objects.
(j) Objects from the same class do not share the same definition of attributes and behaviors.
Chapter 1: Introduction to Object Oriented Programming Concepts – Assignment 2
8. What is an abstraction?
9. What is encapsulation?
(vi). A program that translates code written in a high-level language into machine code is called
____________________
(a) Assembler
(b) Linker
(c) Compiler
(d) None of these
(vii). A program that translates an assembly language program into machine code is called a/an
____________________
(a) Assembler
(b) Linker
(c) Compiler
(d) None of these
(a) Attributes
(b) State
(c) Behavior
(d) All of these
(iii). ________________ represents an entity in the real-world with its identity and behavior.
(a) A class
(b) An object
(c) A procedure
(d) A method
(iv). ________________ is a template to create similar objects that share common characteristics and
behavior.
(a) A function
(b) A procedure
(c) An attribute
(d) A class
(v). The values of an object's _____________ represent the state of the object.
(a) Methods
(b) Procedures
(c) Attributes
(d) Classes
(a) Instance
(b) Behavior
(c) Attribute
(d) State
(a) Keyword
(b) Identifiers
(c) Operators
(d) Procedure
(a) character
(b) break
(c) object
(d) attribute
(a) _age
(b) $Amount
(c) 9thClass
(d) nullValue
(a) 1999
(b) 1999999
(c) 199 99
(d) 199
(viii). Which of the following is not a character literal?
(a) '\t'
(b) "t"
(c) 't'
(d) All of these
(a) ;
(b) .
(c) ,
(d) All of these
(a) boolean
(b) short
(c) float
(d) class
(xi). Which of the following is the size of a long data type in Java?
(a) 32 bits
(b) 64 bits
(c) 48 bits
(d) Long data type is not supported in Java.
(xii). Which of the following is the size of a Boolean data type in Java?
(a) 1 bit
(b) 16 bits
(c) 8 bits
(d) Boolean data type doesn't take any space in memory.
(a) Java supports the use of the ASCII character set only.
(f) The boolean data types are used for storing logical values.
(j) The modifier final can be applied to a variable declaration to ensure that the value stored in the variable
cannot be changed after the variable has been initialized.
Chapter 4: Values and Data Types – Assignment 2
1. What is Unicode?
6. What is an identifier? What is the identifier formatting rule of Java? OR What are the rules for naming a
variable?
8. What are literals? How many types of integer literals are available in Java?
10. What do you mean by Escape sequence and name few escape sequences in Java?
11. What is meant by a floating constant in Java? How many ways can a floating constant be represented into?
13. Write the following real constants into fractional form: 0.113E04, 0.417E-04, 0.4E-05, 0.123E02
14. What is a type or „Data Type‟? How this term is related to programming?
17. How many bytes occupied by the following data types: byte, short, int, long, float, double, char, boolean.
18. What is the range of the following data types: byte, short, int, long, float, double, char, boolean.
20. What do you mean by variables? What do you mean by dynamic initialization of a variable?
22. How can you change a variable to a constant? Give an example. Ans. The keyword final makes a variable
as constant, so that the its value cannot be changed during program execution. e.g final double rate=5.5;
Chapter 5: Operators and Expressions – Assignment 1
(i). An operator taking only single operand for its operation is called ...........
1. AND
2. %
3. ==
4. !
1. <=
2. !==
3. !=
4. ==
1. i++
2. i += 1
3. ++i
4. All of these
1. sum = 13
2. sum = 14
3. sum = 15
4. sum = 16
1. 0
2. 1
3. false
4. true
1. 0
2. 1
3. false
4. true
(viii). The statement (1==1)? 1: 0 evaluates to ...........
1. 0
2. 1
3. false
4. true
1. 4
2. 3
3. 2
4. 1
1. 4
2. 3
3. 0
4. 1
(xi). The statement System.out.println("six " + 3 + 3); gives the output ...........
1. six 33
2. six 6
3. 33 six
4. 6 six
1. 6
2. 8
3. 4
4. None of these
4. What is increment operator? What are postfix and prefix increment operators?
5. Find the value of x after evaluating x += x++ + –x + 4 where x=3 before the evaluation. Explain your
answer.
11. What do you mean by precedence? Illustrate with the help of example
13. What do you mean by constant? How you declare a variable as constant variables.
14. What do you mean by type conversion? What is the difference between implicit and explicit type
conversion explain with example.
(i). A method that does not return a value has a ______________ return type.
(a) Boolean
(b) class
(c) int
(d) void
(v). The parameters that are passed to the method when it is invoked are called _____________________
(a) Windows
(b) Multiple programs
(c) Class
(d) Method or block it is declared in
1. //
2. /* */
3. \\
4. Both A and B
1. import
2. export
3. include
4. impart
1. Comma
2. Whitespace
3. Colon
4. There is no default delimiter.
(iv). Which package would you import to display the date and time?
1. java.util
2. java.Date
3. java.io
4. java.lang
(v). Which package would you import for the Scanner class?
1. java.util.*
2. java.awt.*
3. java.io.*
4. java.lang.*
a. What are the different types of variables? How are they initialized?
b. What are the default values of the following primitive types:
i. boolean
ii. int
iii. char
iv. long
v. float
c. What is the default value of reference data type ?
d. What are the different ways to input values in Java?
e. What are the advantages of input through Scanner class?
f. Differentiate between next( ) and nextLine( ).
g. What is the function of a Scanner class? In which package does it belong?
h. Name the functions of the Scanner that is used to:
i. Accept a number of long data type
ii. Accept a group of alphabets.
i. What is a bug? What is debugging?
j. What is the different type of errors that may occur in a Java program?
k. 11.What are syntax errors? Give two examples
l. 12.What are run-time errors? Give two examples.
m. 13.What are logical errors. Give examples.
n. Write the difference between close( ) and exit( ).
Chapter 7: Input in Java – Assignment 1
Q1. Multiple Choice Questions
1. //
2. /* */
3. \\
4. Both A and B
1. import
2. export
3. include
4. impart
1. Comma
2. Whitespace
3. Colon
4. There is no default delimiter.
(iv). Which package would you import to display the date and time?
1. java.util
2. java.Date
3. java.io
4. java.lang
(v). Which package would you import for the Scanner class?
1. java.util.*
2. java.awt.*
3. java.io.*
4. java.lang.*
(c) Explain the statement, "a well-documented code is as important as the correctly working code".
(d) How can you write single line comments in Java?
(e) Explain data input technique in a program using the Scanner class.
(f) Distinguish between the following:
i. next() and nextLine()
ii. next() and next().charAt(0)
(g) What are delimiters? Which is the default delimiter used in the Scanner class?
(h) What are errors in a program?
(i) Explain the following terms, giving an example of each.
i. Syntax error
ii. Runtime error
iii. Logical error
( j) A program has compiled successfully without any errors. Does this mean the program is error free?
Explain.
(k) Write a program in Java that uses 'input using initialisation' to calculate the Simple Interest and the
Total Amount with the given values:
i. Principle Amount = Rs. 20000
ii. Rate = 8.9%
iii. Time = 3 years
(l) Write a program in Java that accepts the seconds as input and converts them into the corresponding
number of hours, minutes and seconds. A sample output is shown below:
(m) Write a program in java to input the temperature in Fahrenheit, convert it into Celsius and display the
value in the Terminal window. A sample output is displayed below:
1. java.io
2. java.lang
3. java.util
4. java.sys
1. 3
2. 3.0
3. 3.00
4. All of these
1. 46.6
2. 46.5
3. 47.0
4. 46.0
1. -9.99
2. 9.99
3. 0.99
4. None of these
(v). Which of the following is a method to find the square root of a number?
1. FindSquareroot(x)
2. Sqrt(x)
3. Math.Square(x)
4. Math.sqrt(x)
1. 0.0
2. 1.0
3. 2.0
4. -1.0
( a ) Math.sqrt()
( b ) Math.cbrt()
( c ) Math.random()
( d ) Math.round()
( a ) | x3 −y2 −2xy |
( b ) π (z4−2π)
6
( c ) √ (z 2−π )
3
( d ) √ ( x3 – y3 )
4
( e ) amount ∗ rate
1
1- n
(1+rate)
(v). Write a program in Java to find the minimum of three numbers using Math.min() method.
(vi). Write a program to print:
( a ) p to the power q
( b ) the square root of p
(a) <=
(b) ||
(c) &&
(d) ? :
int a = 1;
int b = 2;
if (a == b)
System.out.println ("Both values are equal");
else
System.out.println ("Values are not equal");
if ( c > d)
x = c;
else
x = d;
(iv). Choose the correct option if the code mentioned above is rewritten using the ternary operator:
(a) x = (c >d) ? c : d;
(b) x = (c >d) ? d : c;
(c) x = (c >d) ? c : c;
(d) x = (c >d) ? d : d;
if ((a > b) && (a > c)), then which of the following statements is true?
int val = 2;
switch (val)
{
case 1: System.out.println("Case 1");
break;
case 2: System.out.println("Case 2");
break;
default: System.out.println("No match found");
break;
}
1. a compound statements
2. an empty statement
3. a null statement
4. a void statement
1. default
2. case
3. switch
4. None of these
1. if-else
2. for loop
3. if-else-if ladder
4. switch
1. break
2. continue
3. case
4. default
Chapter 9: Conditional Constructs in Java – Assignment 2
if (choice == 0)
System.out.println("You selected Blue");
else if (choice == 1)
System.out.println("You selected Cyan");
else if (choice == 2)
System.out.println("You selected Red");
else if (choice == 3)
System.out.println("You selected Magenta");
else if (choice == 4)
System.out.println("You selected Green");
else if (choice == 5)
System.out.println("You selected Yellow");
else
System.out.println("Invalid choice");
switch (choice)
{
case 0:
case 1:
x = 11;
y = 22;
break;
case 2:
x = 33;
y = 44;
break;
default:
y = 55;
break;
}
(vi). Write an if statement to find the smallest of the three given integers using the min() method of the Math
class.
(vii). Using the switch statement in Java, write a program to display the color of the spectrum (VIBGYOR)
according to the user's choice.
(viii). Employees at Arkenstone Consulting earn the basic hourly wage of Rs.500. In addition to this, they
also receive a commission on the sales they generate while tending the counter. The commission given to
them is calculated according to the following table:
Write a program in Java that inputs the number of hours worked and the total sales. Compute the
wages of the employees.
(ix). Write a program in Java to compute the perimeter and area of a triangle, with its three sides given as a,
b, and c using the following formulas:
Perimeter=a + b + c
Area = √ s (s−a)(s−b)(s−c )
Where s= a + b + c
2
(x). Mayur Transport Company charges for parcels as per the following tariff:
Weight Charges
Write a program in Java to calculate the charge for a parcel, taking the weight of the parcel as an input.
(xi). The electricity board charges the bill according to the number of units consumed and the rate as given
below:
Write a program in Java to accept the total units consumed by a customer and calculate the bill. Assume
that a meter rent of Rs. 500 is charged from the customer.
(xii). Write a menu driven program to accept a number from the user and check whether it is a Buzz number
or an Automorphic number.
(a) Automorphic number is a number, whose square's last digit(s) are equal to that number. For
example, 25 is an automorphic number, as its square is 625 and 25 is present as the last two digits.
( b ) Buzz number is a number, that ends with 7 or is divisible by 7.
(xiii). Write a program in Java to accept three numbers and check whether they are Pythagorean Triplet or
not. The program must display the message accordingly. [Hint: h2=p2+b2]
(xiv). A cloth showroom has announced the following festival discounts on the purchase of items based on
the total cost of the items purchased:
Write a program to input the total cost and to compute and display the amount to be paid by the
customer availing the discount.
(xv). A box of cookies can hold 24 cookies, and a container can hold 75 boxes of cookies. Write a program
that prompts the user to enter the total number of cookies, the number of cookies in each box, and the
number of cookies boxes in a container. The program then outputs the number of boxes and the number of
containers required to ship the cookies.
(xvi). A special two-digit number is such that when the sum of its digits is added to the product of its digits,
the result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of digits = 5 * 9 = 45
Sum of the sum of digits and product of digits = 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If the
value is equal to the input number, display the message "Special 2 - digit number" otherwise, display the
message "Not a special two-digit number".
1. To check and display whether a number input by the user is a composite number or not.
A number is said to be composite, if it has one or more than one factors excluding 1 and the number
itself.
Example: 4, 6, 8, 9...
2. To find the smallest digit of an integer that is input:
Sample input: 6524
Sample output: Smallest digit is 2
For an incorrect choice, an appropriate error message should be displayed.
Chapter 10: Iterative Constructs in Java – Assignment 1
(a) for
(b) while
(c) do-while
(d) None of these
(a) for
(b) do-while
(c) while
(d) None of these
(a) repeat
(b) while
(c) do-while
(d) for
(a) return
(b) jump
(c) break
(d) continue
(v). How many times will the following code print "Hello"?
(a) 0
(b) 1
(c) 5
(d) 4
(a) 5
(b) 0
(c) 15
(d) Infinite loop
(a) 4
(b) 5
(c) 0
(d) 10
(i). To execute a do-while loop, the condition must be true in the beginning.
(ii). The while loop is an exit-controlled loop.
(iii). The while part of a do-while statement must be terminated by a semicolon.
(iv). The continue statement terminates the current loop and then continues from the statement
immediately following the current loop.
(v). The return statement is a jump statement.
(vi). The for loop may contain multiple initializations and updates.
(vii). A loop that never terminates is called an empty loop.
(viii). The do-while loop executes at least once even if the condition is false.
Chapter 10: Iterative Constructs in Java – Assignment 2
Answer the following Questions
1. What are iteration statements? Name the iteration statements provided by Java?
2. Name the Elements that Control a Loop.
3. What is the difference between entry controlled and exit controlled loop? or What is the difference
between while and do-while loop?
4. 4. Explain the difference between break and continue with an example.
5. Compare and discuss the suitability of three loops in different situation?
6. Explain the term for loop with an example.
7. Give an example to show how multiple initializations and updations are performed in a for-loop.
8. What do you mean by an infinite loop? Give an example.
9. Differentiate Null loop and Infinite loop.
10. What do you mean by delay loop?
11. Compare loops according to its usage.
12. Give the general syntax of a do-while loop. How do you create infinite loops using do-while loop
structure?
13. Give the general syntax of a while-loop. How do you create infinite loops using a while loop structure?
14. State one similarity and one difference between while and do-while loop.
15. Name two jump statements and their use.
Chapter 11: Nested for Loops – Assignment 1
Q5. Give the output of the following snippets based on nested loops
(i). int i,j;
for (i=0; i<4; i++)
{
for (j=i; j>=0; j--)
System.out.print(j);
System.out.println();
}
(ii).int y,p;
for (int x=1; x<=3; x++)
{
for (y=1; y<=2; y++)
{
p = x * y;
System.out.print(p);
}
System.out.println( );
}
(iv). Examine the following code. How many times will the nested loop run?
(a) 3
(b) 6
(c) 1
(d) 9
(vi). Examine the following code. Is there anything that will prevent it from processing?
(ix). Which loop construct in Java is best suited when the number of iterations is unknown?
( a ) for loop
( b ) while loop
( c ) do-while loop
( d ) none
(x).What is the key difference between a while loop and a do-while loop in Java?
( a ) The syntax used to define the loop
( b ) The number of iterations performed
( c ) The condition check timing
( d ) The ability to use the break statement
(xi). Which loop construct guarantees that the loop body is executed at least once?
( a ) for loop
( b ) while loop
( c ) do-while loop
( d ) continue statement
(xiv).Which loop construct is best suited for iterating over an array or a collection?
( a ) for loop
( b ) while loop
( c ) do-while loop
( d ) continue statement
(xv). Which type of loop is best known for its boolean condition that controls entry to the loop?
( a ) do-while loop
( b ) for (traditional)
( c ) for-each
( d ) while
(xvii). Which of the following can loop through an array without referring to the elements by index?
( a ) do-while loop
( b ) for (traditional)
( c ) for-each
( d ) while
If the number as well as the reverse is also 'Prime' then display 'Twisted Prime' otherwise 'Not a twisted
Prime'.
Sample Input: 167
Sample Output: 167 and 761 both are prime.
It is a 'Twisted Prime'.
(b)
12345
1234
123
12
1
(c)
54321
5432
543
54
5
(d)
13579
1357
135
13
1
(e)
5
54
543
5432
54321
(f)
12345
2345
345
45
5
(g)
99999
77777
55555
33333
11111
(h)
9
79
579
3579
13579
(i)
9
97
975
9753
97531
(j)
1
23
456
7 8 9 10
11 12 13 14 15