9th computer
Here’s another fresh set of Java questions with options (MCQs + short answer + programming) in the same exam style:
Section A
Question 1 (Choose the correct option)
-
Which keyword is used to inherit a class in Java?
(a) implement (b) extends (c) inherits (d) super -
Which of these is not a primitive data type?
(a) int (b) float (c) String (d) char -
Which operator is used for modulus in Java?
(a) / (b) % (c) * (d) // -
Which loop executes at least once?
(a) for (b) while (c) do-while (d) foreach -
Which package contains the Scanner class?
(a) java.io (b) java.util (c) java.lang (d) java.text -
Which of the following is a valid variable name?
(a) 1value (b) _count (c) class (d) @sum -
Which method of
Math
class returns the maximum of two numbers?
(a) Math.abs() (b) Math.min() (c) Math.max() (d) Math.sqrt() -
What is the default value of a boolean variable?
(a) 1 (b) 0 (c) true (d) false -
Which operator is used to concatenate strings in Java?
(a) + (b) & (c) , (d) concat -
Which of these is a valid access modifier in Java?
(a) friend (b) public (c) global (d) internal
Question 2 (Answer briefly)
-
Write a statement to declare a
float
variable named price with value 99.5. -
Which method of Scanner is used to read an integer value?
-
What is the difference between
==
and.equals()
in Java? -
Write the syntax of an
if-else
statement. -
Which loop is best suited when the number of iterations is known?
-
What will be the output of the following code?
int x = 7, y = 2; System.out.println(x / y);
-
Name two features of Object-Oriented Programming.
-
Write the output of
Math.pow(2, 4)
. -
Which keyword is used to exit from a loop immediately?
-
What will be the value of
a
after executing the code?int a = 5; ++a; a++;
Section B
Question 3
a) Write a program to calculate the area of a triangle using the formula ½ × base × height
.
b) Write a program to calculate the perimeter of a square.
Question 4
Write a program to input two numbers and display the greater of the two.
Question 5
a) Write a program to demonstrate the use of assignment operators (+=
, -=
, *=
).
b) Write a program to demonstrate the use of bitwise operators (&
, |
, ^
).
Question 6
Write a program to input your name, age, and grade, then display them in a formatted way.
Question 7
a) Write a program to convert kilometers into meters and centimeters.
b) Write a program to find the cube root of a number using Math.cbrt()
.
Question 8
Write a program to calculate the average of n numbers entered by the user.
Do you want me to prepare one more brand-new set with completely different topics (like arrays, strings, loops) for variety?
Comments
Post a Comment