9th computer

Section A

Question 1

  1. Which of these is not a Java keyword?
    a) class b) new c) then d) void

  2. Which operator is used for division in Java?
    a) ÷ b) div c) / d) %

  3. Which data type can store true/false values in Java?
    a) int b) boolean c) char d) String

  4. Which of these is the correct way to declare an array of 5 integers?
    a) int arr[5]; b) int arr = new int[5]; c) int arr[ ] = new int[5]; d) int[5] arr;

  5. Which method of Scanner is used to read a floating-point number?
    a) nextFloat() b) readFloat() c) getFloat() d) float()

  6. Which access modifier makes members visible everywhere?
    a) private b) protected c) public d) default

  7. Which of the following is a wrapper class in Java?
    a) int b) char c) Integer d) String

  8. Which package is imported automatically in every Java program?
    a) java.io b) java.lang c) java.util d) java.net

  9. Which operator is used for logical OR in Java?
    a) || b) or c) | d) +

  10. Which of these is not an arithmetic operator?
    a) + b) - c) * d) &&

  11. Which keyword is used to create an object in Java?
    a) object b) class c) new d) this

  12. Which operator is used to check if two objects are equal in content?
    a) == b) = c) equals() d) :=

  13. Which type casting is also called “type promotion”?
    a) Narrowing b) Explicit c) Widening d) Manual

  14. What will be the result of 15 / 4 in Java?
    a) 3.75 b) 3 c) 4 d) 15

  15. What is the default value of an int variable in Java?
    a) 0 b) null c) garbage d) 1

  16. Which of these is not a valid identifier in Java?
    a) myNumber b) _value c) 123num d) total

  17. Which keyword is used to stop the execution of a loop?
    a) exit b) break c) stop d) continue

  18. Which is the correct way to declare a constant PI with value 3.14?
    a) const double PI = 3.14; b) double PI = 3.14; c) final double PI = 3.14; d) constant PI = 3.14;

  19. Which method of Scanner is used to read a single word?
    a) nextWord() b) next() c) get() d) read()

  20. Which of the following is not an OOP principle?
    a) Polymorphism b) Abstraction c) Compilation d) Encapsulation


Question 2

  1. Write a Java statement to declare an integer variable named age and assign it the value 18.

  2. Differentiate between while loop and do-while loop.

  3. Which Scanner method is used to read a long value from the user?
    a) nextLong() b) readLong() c) getLong() d) long()

  4. Name two data types in Java that can store whole numbers.

  5. Write the syntax to read a double value from the user using the Scanner class.

  6. Which keyword is used to define a class in Java? Give an example.

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

    int a = 10;
    a -= 4;
    System.out.println(a);
    

    a) 14 b) 6 c) 4 d) 10

  8. Write the output of Math.min(25, 40) and Math.abs(-12).

  9. Which OOP pillar allows using the same method name but with different parameters?
    a) Abstraction b) Inheritance c) Polymorphism d) Encapsulation

  10. What is the output of the following code?

    int a = 5;
    int b = a++;
    System.out.println(b);
    

    a) 5 b) 6 c) 4 d) Error


Section B

Question 3
a) Write a program to calculate the area and circumference of a circle.
b) Write a program to calculate the perimeter of a rectangle.

Question 4
Write a program to input three numbers and display the largest and smallest among them.

Question 5
a) Write a program to demonstrate the use of logical operators (&&, ||, !).
b) Write a program to demonstrate the use of relational operators (<, >, ==, !=).

Question 6
Write a program to input the marks of 5 subjects and display the total marks and percentage.

Question 7
a) Write a program to convert temperature from Fahrenheit to Celsius.
b) Write a program to find the square root of a number using Math.sqrt().

Question 8
Write a program to calculate compound interest based on user input for principal, rate, and time.


πŸ‘‰ Do you want me to now create a third full set of such questions with options (so you have multiple practice papers ready)?

Comments

Popular posts from this blog

class 8 computer chapter 5

CLASS 8 COMPUTER

Class 5 computer chapter 4