0% found this document useful (0 votes)
29 views4 pages

Java Practice Questions

The document contains a set of Java programming practice questions along with an answer key. It covers topics such as variable declaration, user input, loops, boolean values, and data types. Each question is multiple choice, testing fundamental knowledge of Java programming concepts.

Uploaded by

eseosaosaghae4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views4 pages

Java Practice Questions

The document contains a set of Java programming practice questions along with an answer key. It covers topics such as variable declaration, user input, loops, boolean values, and data types. Each question is multiple choice, testing fundamental knowledge of Java programming concepts.

Uploaded by

eseosaosaghae4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Programming Practice Questions

1. What is the correct syntax to declare a variable that stores an integer value in Java?

A) int number;

B) integer number;

C) num int;

D) number int;

2. Which Java class is commonly used to read user input from the console?

A) System.in

B) Scanner

C) InputReader

D) BufferedReader

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

int x = 5;

System.out.println(++x);

A) 5

B) 6

C) 4

D) Compilation error

4. Which loop is guaranteed to execute at least once?

A) for loop

B) while loop

C) do-while loop

D) foreach loop
5. In Java, what is the default value of a boolean variable?

A) true

B) false

C) 0

D) null

6. What is the output of the following code snippet?

int a = 10;

int b = 20;

System.out.println(a + b);

A) 1020

B) 30

C) a + b

D) Compilation error

7. Which keyword is used to create a subclass in Java?

A) implements

B) inherits

C) extends

D) super

8. What does the break statement do in a loop?

A) Skips the current iteration

B) Exits the loop entirely

C) Pauses the loop

D) Restarts the loop

9. Which of the following is not a primitive data type in Java?


A) int

B) String

C) char

D) boolean

10. How do you start the execution of a Java program?

A) By calling the start() method

B) By defining the main() method

C) By creating a constructor

D) By importing the java.main package


Answer Key

1. A

2. B

3. B

4. C

5. B

6. B

7. C

8. B

9. B

10. B

You might also like