Java MCQ
1. In Java, which class is used to represent a sequence of characters as a string?
A. String
B. StringBuilder
C. StringSequence
D. StringArray
2. What is the correct way to create a new empty String object in Java?
A. String emptyString = "";
B. String emptyString = new String();
C. String emptyString = "";
D. String emptyString = null;
E. Both A and B
3. In Java, which operator is used to concatenate two strings?
A. +
Β. &
C. O,
D.I
4. Which of the following methods is used to compare two strings for equality in Java?
A. equals()
B. compareTo()
C. equalsIgnoreCase()
D. compare()
5. What does the length() method of a String object in Java return?
A. The capacity of the string
B. The size of the string
C. The length of the string
D. The index of the last character
6. Which of the following is true about Java strings?
A. Strings are mutable.
B. Strings can contain only letters.
C. Strings can have a null value.
D. Strings are implemented as arrays of characters.
7. How do you convert a string to lowercase in Java?
A. [Link]()
B. [Link]()
C. [Link]()
D. [Link]()
8. What is the purpose of the charAt() method of a String object in Java?
A. To add a character to the string
B. To remove a character from the string
C. To get the character at a specific index
D. To get the length of the string
9. Which method is used to find the index of the first occurrence of a specified character in a
string in Java?
A. findIndex()
B. indexOf()
C. search()
D. findCharacter()
10. In Java, what is the result of the expression "Hello".substring(1, 4)?
A. "Hel"
B. "H"
C. "ell"
D. "llo”
11. What is the purpose of the trim() method of a String object in Java?
A. To remove all spaces from the string
B. To concatenate two strings
C. To extract a substring from the
string
D. To remove leading and trailing whitespace
12. Which of the following methods is used to replace all occurrences of a specified
character in a string in Java?
A. replace()
B. replaceAll()
C. replaceChar()
D. replaceAllOccurrences()
13. Which of these is not a feature of Java?
[Link]-oriented
[Link]-independent
[Link]
[Link] language
Answer - c
14. Which component of Java is responsible for running the compiled Java bytecode?
[Link]
[Link]
[Link]
[Link]
Answer: [Link]
15. Which feature of Java makes it possible to run a Java program on different platforms?
[Link]-Oriented
[Link]-Independent
[Link]
[Link] Management
Answer: [Link]-Independent
16. How do I comment on a block of code in Java?
A./*comment*/
B.//comment
C.!--comment--
D.%comment
Answer: A./*comment*/
17. What is the result of this operation in Java?
(int)(7.9)
A.7
B.7.9
C.8
[Link] Error
Answer: A.7
18. Which keyword is used in Java to implement inheritance between classes?
A. extends
B. implements
C. inherits
D. inheritsFrom
Answer - A
19. What is inheritance in Java?
A. A mechanism to create new classes from existing ones
B. A way to implement polymorphism
C. A technique to achieve encapsulation
D. A feature for multiple object creation
Answer: A
20. What is single inheritance?
A. One class inherits from multiple classes
B. A class inherits from only one class
C. Multiple classes inherit from a single class
D. A class inherits from itself
Answer: B
21. What is hierarchical inheritance?
A. One class inherits from multiple classes
B. A class inherits from only one class
C. Multiple classes inherit from a single class
D. A class inherits from itself
Answer: C
22. What is multilevel inheritance?
A. One class inherits from multiple classes
B. A class inherits from only one class
C. Multiple classes inherit from a single class
D. A class inherits from itself
Answer: A
23. Can a child class access private members of its parent class?
A. Yes, always
B. No, never
C. Only if the child class is in the same package
D. Only if the child class is in a different package
Answer: B
24. What is the default access modifier for members of a class in Java?
A. public
B. private
C. protected
D. package-private (default)
Answer: D
25. What is polymorphism?
A. The ability of objects to take on different forms
B. The ability of objects to have different behaviours
C. The ability of objects to be used interchangeably
D. All of the above
Answer: D
26. What is a package in Java?
A. A collection of related classes and interfaces
B. A unit of execution in Java
C. A data structure for storing objects
D. A keyword used for access control
Answer: A
27. How do you create a package in Java?
A. Using the package keyword
B. Using the class keyword
C. Using the interface keyword
D. Using the import keyword
Answer: A
28. What is the default package in Java?
A. [Link]
B. [Link]
C. [Link]
D. No default package exists
Answer: D
29. How do you import a class from another package?
A. Using the package keyword
B. Using the class keyword
C. Using the interface keyword
D. Using the import keyword
Answer: D
30. What is the purpose of the [Link] package?
A. Provides utility classes for common operations
B. Provides classes for input/output operations
C. Provides classes for networking
D. Provides classes for mathematical operations
Answer: A
31. Can a class be defined within a package without a package declaration?
A. Yes, always
B. No, never
C. Only if it's in the same directory as the package declaration
D. Only if it's in a different directory than the package declaration
Answer: A
32. Which method in the Math class returns the absolute value of a number?
A. abs()
B. ceil()
C. floor()
D. round()
Answer: A
33. What is the purpose of the [Link]() method?
A. Calculates the square root of a number
B. Raises a number to a power
C. Finds the natural logarithm of a number
D. Calculates the sine of an angle
Answer: B
34. Which method in the Math class returns the smallest integer greater than or equal to the
specified number?
A. abs()
B. ceil()
C. floor()
D. round()
Answer: B
35. What is the purpose of the [Link]() method?
A. Calculates the square root of a number
B. Raises a number to a power
C. Finds the natural logarithm of a number
D. Calculates the sine of an angle
Answer: A
36. Which method in the Math class returns the largest integer less than or equal to the
specified number?
A. abs()
B. ceil()
C. floor()
D. round()
Answer: C
37. Who created the Java programming language?
A. Bill Gates
B. Linus Torvalds
C. James Gosling
D. Dennis Ritchie
Answer: C
38. In what year was Java first released?
A. 1990
B. 1991
C. 1995
D. 1996
Answer: C
39. For what purpose was Java originally designed?
A. To create operating systems
B. To develop web applications
C. To create video games
D. To control household appliances
Answer: D
40. What is the "write once, run anywhere" (WORA) principle of Java?
A. Java programs can be compiled and run on any platform
B. Java programs can only be run on Windows
C. Java programs can only be run on Linux
D. Java programs can only be run on macOS
Answer: A
41. Which company acquired Sun Microsystems, the original creator of Java?
A. Oracle
B. Microsoft
C. Apple
D. Google
Answer: A
42. What is the purpose of the Java Virtual Machine (JVM)?
A. Interprets and executes Java bytecode
B. Compiles Java code into machine code
C. Creates Java applications
D. Provides a graphical user interface for Java development
Answer: A
43. What is the name of the standard library of classes and interfaces in Java?
A. Java API
B. Java SDK
C. Java SE
D. Java EE
Answer: A
44. In what year was the first public release of Java, known as Java 1.0, released?
A. 1995
B. 1996
C. 1997
D. 1998
Answer: B
45. What was the major new feature introduced in Java 2 (also known as J2SE 1.2)?
A. Generics
B. Annotations
C. Enhanced for loop
D. Swing GUI toolkit
Answer: D
01.JDK - Java Development Kit.
02.JRE - Java Runtime Environment.
03.JVM - Java Virtual Machine.
04.JDBC - Java Database Connectivity.
05.API - Application Programming Interface
06.ODBC - Open Database Connectivity
07.COBRA - Common Object Request Broker Architecture
08.POS - Persistent Object Service
09.CLI - command-line interface
10.WORA - Write once Run Anywhere
11.IDE - integrated development environment
12.OOP - Object-Oriented Programming
13.POP - Procedural Oriented Programming
14.ASCII - American Standard Code for Information Interchange
15.ISCII - Indian Standard Code for Information Interchange
16.JAVA - Just Another Virtual Accelerator