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)

  1. Which keyword is used to inherit a class in Java?
    (a) implement (b) extends (c) inherits (d) super

  2. Which of these is not a primitive data type?
    (a) int (b) float (c) String (d) char

  3. Which operator is used for modulus in Java?
    (a) / (b) % (c) * (d) //

  4. Which loop executes at least once?
    (a) for (b) while (c) do-while (d) foreach

  5. Which package contains the Scanner class?
    (a) java.io (b) java.util (c) java.lang (d) java.text

  6. Which of the following is a valid variable name?
    (a) 1value (b) _count (c) class (d) @sum

  7. Which method of Math class returns the maximum of two numbers?
    (a) Math.abs() (b) Math.min() (c) Math.max() (d) Math.sqrt()

  8. What is the default value of a boolean variable?
    (a) 1 (b) 0 (c) true (d) false

  9. Which operator is used to concatenate strings in Java?
    (a) + (b) & (c) , (d) concat

  10. Which of these is a valid access modifier in Java?
    (a) friend (b) public (c) global (d) internal


Question 2 (Answer briefly)

  1. Write a statement to declare a float variable named price with value 99.5.

  2. Which method of Scanner is used to read an integer value?

  3. What is the difference between == and .equals() in Java?

  4. Write the syntax of an if-else statement.

  5. Which loop is best suited when the number of iterations is known?

  6. What will be the output of the following code?

    int x = 7, y = 2;
    System.out.println(x / y);
    
  7. Name two features of Object-Oriented Programming.

  8. Write the output of Math.pow(2, 4).

  9. Which keyword is used to exit from a loop immediately?

  10. 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

Popular posts from this blog

class 8 computer chapter 5

CLASS 8 COMPUTER

Class 5 computer chapter 4