800+ FREE JAVA PROGRAMMING MCQs

This website offers multiple-choice questions (MCQs) related to the Java programming language, designed to test and improve learners' knowledge and understanding of Java concepts. It is a helpful resource for Java learners to assess their skills and track their progress in a concise and accessible format.



MCQss provide latest and authentic java multiple choice questions. The users receive instant feedback of the answers. No registration is required to take the test, and it is completely free of cost.

Java programming online multiple choice questions

What is Java?

A. A programming language

B. A software application

C. A hardware device

D. An operating system

Answer: A


What is the purpose of the "public static void main" method in Java?

A. It is the entry point of a Java program.

B. It is used to print text to the console.

C. It is used to declare variables.

D. It is used to create objects.

Answer: A


What is the correct syntax to declare an array in Java?

A. int[] arrayName = new int[];

B. int arrayName[] = new int[];

C. int[] arrayName = new int[length];

D. int arrayName[] = new int[length];

Answer: C


What is the difference between an abstract class and an interface in Java?

A. An abstract class can be instantiated, while an interface cannot.

B. An abstract class can have method implementations, while an interface cannot.

C. An interface can have fields, while an abstract class cannot.

D. An abstract class can have private methods, while an interface cannot.

Answer: B


What is the output of the following code?

int x = 5;

System.out.println(++x);

A. 4

B. 5

C. 6

D. 7


Answer: C


Which of the following is a valid way to declare a constant in Java?

A. final int constant = 5;

B. int constant = 5;

C. static int constant = 5;

D. const int constant = 5;

Answer: A


What is the purpose of the "this" keyword in Java?

A. It refers to the current object.

B. It is used to declare a new object.

C. It is used to access static variables.

D. It is used to access private variables.

Answer: A


What is the output of the following code?

String str = "hello";

System.out.println(str.charAt(2));

A. l

B. o

C. e

D. h


Answer: C


What is the correct syntax to create a new instance of a class in Java?

A. ClassName objectName = new ClassName();

B. objectName = new ClassName();

C. objectName.ClassName = new ClassName();

D. ClassName objectName = ClassName();

Answer: A


Which of the following is not a Java keyword?

A. final

B. static

C. const

D. synchronized

Answer: C


What is the output of the following code?

int x = 5;

int y = 7;

System.out.println(x + y);

A. 5

B. 7

C. 12

D. 35


Answer: C


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

A. int

B. boolean

C. string

D. double

Answer: C


What is the purpose of the "super" keyword in Java?

A. It refers to the current object.

B. It is used to declare a new object.

C. It is used to access static variables.

D. It is used to call a superclass constructor or method.

Answer: D


What is the purpose of the "try-catch" block in Java?

A. It is used to declare variables.

B. It is used to create objects.

C. It is used to handle exceptions.

D. It is used to define methods.

Answer: C


What is the output of the following code?

String str = "hello";

System.out.println(str.length());

A. 4

B. 5

C. 6

D. 7


Answer: B


What is the purpose of the "break" statement in Java?

A. It is used to terminate a loop.

B. It is used to skip the current iteration of a loop.

C. It is used to continue to the next iteration of a loop.

D. It is used to define a switch case.

Answer: A


Which of the following is an example of a conditional statement in Java?

A. for loop

B. while loop

C. if statement

D. switch statement

Answer: C


What is the output of the following code?

int x = 5;

System.out.println(x++);

A. 4

B. 5

C. 6

D. 7


Answer: B


What is the purpose of the "extends" keyword in Java?

A. It is used to define a superclass.

B. It is used to define a subclass.

C. It is used to define an interface.

D. It is used to define a method.

Answer: B


What is the output of the following code?

int x = 5;

int y = 7;

System.out.println(x * y);

A. 5

B. 7

C. 12

D. 35


Answer: D


What is the purpose of the "finally" block in Java?

A. It is used to define methods.

B. It is used to handle exceptions.

C. It is used to create objects.

D. It is used to declare variables.

Answer: B


What is the output of the following code?

String str = "hello";

System.out.println(str.toUpperCase());

A. HELLO

B. hello

C. hElLo

D. HeLlO


Answer: A


Which of the following is not a control flow statement in Java?

A. break

B. continue

C. return

D. print

Answer: D


What is the output of the following code?

int x = 5;

int y = 7;

System.out.println(x == y);

A. true

B. false

C. compile-time error

D. runtime error


Answer: B


Which of the following is not a modifier keyword in Java?

A. public

B. static

C. method

D. final

Answer: C


What is the output of the following code?

String str = "hello";

System.out.println(str.indexOf('l'));

A. 1

B. 2

C. 3

D. 4


Answer: B


What is the purpose of the "new" keyword in Java?

A. It is used to declare variables.

B. It is used to create objects.

C. It is used to define methods.

D. It is used to access static variables.

Answer: B


What is the output of the following code?

String str = "hello";

System.out.println(str.concat(" world"));

A. hello world

B. hello

C. world

D. helloworld

Answer: A


Note:

Visit this link to practice our 800+ Free Jave online test mcqs.

800+ FREE JAVA MCQs  





Comments

Popular posts from this blog

React js multiple choice questions with answers

1100+ PHP Free Exam Questions And Answers