500+ Java MCQs

Prepare for your Java interviews and exams with our comprehensive collection of 500+ multiple-choice questions. This resource is designed to help you test and improve your knowledge of Java programming concepts, including core Java, object-oriented programming, data structures, algorithms, and more. Whether you are a beginner or an experienced Java developer, these MCQs will challenge your understanding and help you identify areas for improvement. Each question is carefully crafted to assess your problem-solving skills and critical thinking abilities. With this extensive question bank, you can confidently prepare for any Java-related interview or exam. Take advantage of this valuable resource to enhance your Java expertise and increase your chances of success.

Q1. Who is considered the father of Java?

A. Dennis Richie

B. Ken Thompson

C. James Gosling

D. Bjarne Stroupstrup

Ans:: C. James Gosling

Q2. Which of the following statements about the Java language is true?

A. Java supports only Procedural Oriented Programming approach

B. Both Procedural and Object Oriented Programming are supported in Java

C. Java supports only Object Oriented Programming approach

D. None of the Above

Ans:: C. Java supports only Object Oriented Programming approach

Q3. JRE stands for

A. Java Realtime Environment

B. Java Rapid Enterprise

C. Java Runtime Environment

D. None of the above

Ans:: C. Java Runtime Environment

Q4. Java source files are compiled and converted to

A. Object code

B. machine code

C. Bytecode

D. executable file

Ans:: C. Bytecode

Q5. JVM is ___________for bytecode.

A. a compiler

B. an interpreter

C. assembler

D. none of the above

Ans:: B. an interpreter

Q6. What is the size of the int data type in Java?

A. 1 byte

B. 2 bytes

C. 4 bytes

D. 8 bytes

Ans:: C. 4 bytes

Q7. Java is a __________ language?

A. Platform Dependent

B. Platform Independent

C. POP

D. Both A & B

Ans:: B. Platform Independent

Q8. In which year Java was developed?

A. 1995

B. 1975

C. 1994

D. 1980

Ans:: A. 1995

Q9. How many access modifiers are present in Java?

A. 1

B. 3

C. 2

D. 4

Ans:: D. 4 (public, private, default, protected)

Q10.Which of the following is not an access modifier in Java?

A. public

B. protected

C. secure

D. private

Ans:: C. Secure

Q11.Which of the following is not an access modifier in Java?

A. public

B. protected

C. secure

D. private

Ans:: C. Secure

Q12.Which is a valid float literal?

A. 1.23

B. 2

C. 1.23d

D. 1.23f

Ans:: D. 1.23f

Q13.Which of these values can a boolean variable contain?

A. True & False

B. 0 & 1

C. Any integer value.

D. Both a & b

Ans:: A. True & False

Q14.What are the types of memory allocated in memory in java?

A. Heap memory

B. Stack memory

C. Both A and B

D. None of these

Ans:: C. Both A and B

Q15.What makes the Java platform independent?

A. Advanced programming language

B. It uses bytecode for execution

C. Class compilation

D. All of these

Ans:: B. It uses bytecode for execution

Q16.Which of these is an incorrect array declaration?

A. int arr[] = new int[5];

B. int [] arr = new int[5];

C. int arr[]; arr = new int[5];

D. int arr[] = int [5] new;

Ans:: D. int arr[] = int [5] new;

Q17.The keyword used to create a constant variable

A. const

B. static

C. final

D. none of these

Ans:: A. final

Q18.What is stored in the object obj in the following lines of code?

Test obj;

A. Memory address of allocated memory of the object.

B. Null

C. Any arbitrary pointer

D. Garbage

Ans:: B. Null

Q19.What is the entry point of a program in Java?

A. main() method

B. The first line of code

C. Last line of code

D. main class

Ans:: A. main() method

Q20.Can the main() method be overloaded in Java?

A. Yes

B. No

Ans:: A. Yes(Note: We can overload the main method in Java but JVM only calls the original main method, it will never call our overloaded main method.)

Q21.Which class in Java is used to take input from the user?

A. Scanner

B. Input

C. Applier

D. None of these

Ans:: A. Scanner

Q22. Is string mutable in Java?

A. Yes

B. No

Ans:: B. No

Q23.Which of these is a type of variable in Java?

A. Instance Variable

B. Local Variable

C. Static Variable

D. All of these

Ans:: D. All of these

Q24. What will be the output of the below program?

public class Test {

public static void main(String[] args) {

String str = "Hello";

str = "World";

System.out.println(str);

}

}

A. Hello

B. World

C. Error

D. None of these

Ans:: B. World

Q25.What is typecasting in Java?

A. It is converting the type of a variable from one type to another

B. Casting variable to the class

C. Creating a new variable

D. All of these

Ans:: A. It is converting the type of a variable from one type to another

Q26.Which class cannot have a subclass in Java?

A.abstract class

B.parent class

C.final class

D.None of the above

Ans:: C. final class (We can not extend a class if it is a final class)

Q27.Which is the keyword used to inherit a class from another class?

A.Inherits

B.implements

C.extends

D.import

Ans:: B. extends

Q28.What is the use of the final keyword with method definition?

A.to supports method overriding

B.implements dynamic method dispatch

C.Prevent method overriding

D.None of these

Ans:: C.Prevent method overriding

Q29.Identify the type of inheritance when two or more subclasses inherit the properties of a super class.

A.Multiple inheritance

B.Single inheritance

C.Multilevel inheritance

D.Hierarchical inheritance

Ans:: D. Hierarchical inheritance

Q30.Which keyword is used inside a class to refer to its immediate super class?

A.super

B.parent

C.base

D.none of these

Ans:: A. super

Q31.Which of the following is true in the case of abstract class?

A. Abstract constructors cannot be created.

B. Abstract classes can not be inherited.

C. An abstract class contains only abstract methods.

D. All of the above.

Ans:: A. Abstract constructors cannot be created.

Q32. Which of these keywords are used to define an abstract class?

A. abst

B. abstract

C. Abstract

D. abstract class

Ans:: B. abstract

Q33. Which of these is not a correct statement?

A. Every class containing abstract method must be declared abstract.

B. Abstract class defines only the structure of the class not its implementation.

C. Abstract class can be initiated by new operator.

D. Abstract class can be inherited.

Ans:: C. Abstract class can be initiated by new operator.

Q34. Which method defined in the Integer class can be used to convert a whole number in string type to primitive int type?

A. valueOf()

B. intValue()

C. parseInt()

D. getInteger()

Ans:: C. parseInt()

Q35.The method sqrt() is defined in the class

A. System

B. Root

C. Math

D. Arithmetic

Answer» C. Math

Q36. Name the keyword that makes a variable belong to a class, rather than being defined for each instance of the class.

A. static

B. final

C. abstract

D. public

Ans:: A. static

Q37. Variables declared within a class are called

A. Identifier

B. local variable

C. instance variable

D. global variable

Ans:: C. instance variable

Q38. Variables declared within a method or block are called

A. Static variable

B. local variable

C. instance variable

D. global variable

Ans:: B. local variable

Q39. Defining methods with the same name and different numbers of parameters are called

A. Method overriding

B. method overloading

C. Dynamic method dispatch

D. none of the above

Ans:: B. method overloading

Q40. Which is used to initialize the objects.

A. Methods

B. arguments

C. constructors

D. new keyword

Ans:: C. constructors

Q41. What is the return type of Constructors?

A. int

B. float

C. void

D. None of the these

Ans:: D. None of the these

Q42. Which of the following is a method having the same name as that of its class?

A. finalize

B. delete

C. class

D. constructor

Ans:: D. constructor

Q43. Which operator is used by Java run time implementations to free the memory of an object when it is no longer needed?

A. delete

B. free

C. new

D. None of these

Ans:: D. None of these

Q44. Which of these access specifiers must be used for main() method?

A. private

B. public

C. protected

D. None of these

Ans:: B. public

Q45. Which of these is used to access the member of a class before the object of that class is created?

A. public

B. private

C. static

D. protected

Ans:: C. static

Q46. Which keyword is used to create an object?

A. class

B. this

C. new

D. malloc

Ans:: C. new

Q47. Which keyword is used to refer to the current object?

A. class

B. this

C. new

D. malloc

Ans:: B. this

Q48. A Method that is automatically invoked during garbage collection.

A. destructor

B. terminate()

C. finalize()

D. destroy()

Ans:: C. finalize()

Q49. A primitive data type can be passed as an argument into a method.

A. By Value

B. by reference

C. both a & b

D. None of these

Ans:: A. By Value

Q50. Which of these is used as a default for a member of a class if no access specifier is used for it?

A. private

B. public

C. public, within its own package

D. protected

Ans:: C. public, within its own package

Q51. Which of these keywords is used to refer to a member of the base class from a sub-class?

A. upper

B. super

C. this

D. None of these

Ans:: B. super

Q52. Which of these is the correct way of inheriting class A by class B?

A. class B + class A {}

B. class B inherits class A {}

C. class B extends A {}

D. class B extends class A {}

Ans:: C. class B extends A {}

Q53. Which of the following statements are true about interfaces?

A. Methods declared in interfaces are implicitly private.

B. Variables declared in interfaces are implicitly public, static, and final.

C. An interface contains any number of method definitions.

D. The keyword implements indicate that an interface inherits from another.

Ans:: B. Variables declared in interfaces are implicitly public, static, and final.

Q54. Which of these keywords is used to define interfaces in Java?

A. interface

B. Interface

C. intface

D. implements

Ans:: A. interface

Q55. Which of these can be used to fully abstract a class from its implementation?

A. Objects

B. Packages

C. Interfaces

D. None of these

Ans:: C. Interfaces

Q56. Which of these access specifiers can be used for an interface?

A. Public

B. Protected

C. private

D. All of these

Ans:: A. Public

Q57. Which of these keywords is used by a class to use an interface defined previously?

A. import

B. Import

C. implements

D. Implements

Ans:: C. implements

Q58. Which of the following is the correct way of implementing an interface Department by a class Employee?

A. class Employee extends Department{}

B. class Employee implements Department{}

C. class Employee imports Department{}

D. None of these

Ans:: B. class Employee implements Department{}

Q59. Which keyword is used to create a package?

A. import

B. package

C. classpath

D. public

Ans:: B. package

Q60. The modifier which specifies that the member can only be accessed in its own class is.

A. public

B. private

C. protected

D. None of these

Ans:: B. private