100 Java MCQ (Multiple Choice Questions) with Answers

 

1) What is the extension of compiled Java class files?
  1. .java
  2. .class
  3. .txt
  4. .js
Show Answer
Answer: b
Explanation
Java source files use .java. When compiled by javac, they produce bytecode files with the .class extension.


2) Who developed the Java programming language?

  1. Dennis Ritchie
  2. James Gosling
  3. Bjarne Stroustrup
  4. Guido van Rossum
Show Answer
Answer: b
Explanation
Java was created by James Gosling and his team at Sun Microsystems, first released in 1995.


3) Which component of Java is responsible for executing the bytecode?

  1. JDK
  2. JRE
  3. JVM
  4. JIT
Show Answer
Answer: c
Explanation
The JVM (Java Virtual Machine) executes Java bytecode. The JRE includes the JVM and libraries, while the JDK includes the JRE plus development tools.


4) What is the entry point method in a Java application?

  1. public void main(String[] args)
  2. public static void main(String[] args)
  3. private static void main(String[] args)
  4. public static int main(String[] args)
Show Answer
Answer: b
Explanation
The JVM looks for public static void main(String[] args) as the starting point of a standalone Java application.


5) Which keyword is used to inherit a class in Java?

  1. implements
  2. extends
  3. inherits
  4. super
Show Answer
Answer: b
Explanation
extends is used for class inheritance. implements is used when a class implements an interface.


6) What is the default value of a boolean variable in Java?

  1. true
  2. false
  3. 0
  4. null
Show Answer
Answer: b
Explanation
Instance and static boolean fields default to false. Local variables must be explicitly initialized before use.


7) Which of these is a primitive data type in Java?

  1. String
  2. Array
  3. int
  4. Class
Show Answer
Answer: c
Explanation
int is one of Java’s eight primitive types. String, Array, and Class are reference types.


8) Which keyword is used to create an instance of a class?

  1. alloc
  2. new
  3. instance
  4. create
Show Answer
Answer: b
Explanation
The new operator allocates memory and invokes a class constructor to create an object.


9) What is the size of an int variable in Java?

  1. 16 bits
  2. 32 bits
  3. 64 bits
  4. 8 bits
Show Answer
Answer: b
Explanation
An int is a 32-bit signed two’s complement integer in Java.


10) Which keyword is used to make a variable’s value unchangeable?

  1. static
  2. abstract
  3. final
  4. const
Show Answer
Answer: c
Explanation
final makes a variable a constant that cannot be reassigned. const is a reserved keyword in Java but is not used.


11) Which method is used to find the length of a String in Java?

  1. length()
  2. len()
  3. size()
  4. getLength()
Show Answer
Answer: a
Explanation
String.length() returns the number of characters. For arrays, the .length field is used instead.


12) How do you declare an array in Java?

  1. int arr[]
  2. int[] arr
  3. int arr = new int[5]
  4. Both a and b
Show Answer
Answer: d
Explanation
Both int arr[] and int[] arr are valid array declarations. The third option is missing brackets on the type or variable.


13) Which keyword is used to handle exceptions in Java?

  1. catch
  2. throw
  3. try
  4. All of the above
Show Answer
Answer: d
Explanation
Exception handling uses try, catch, throw, throws, and finally.


14) What package is automatically imported into every Java program?

  1. java.util
  2. java.io
  3. java.lang
  4. java.net
Show Answer
Answer: c
Explanation
java.lang is implicitly imported, which is why classes like String, System, and Object are available without an import statement.


15) Which of the following is NOT a Java access modifier?

  1. protected
  2. private
  3. internal
  4. public
Show Answer
Answer: c
Explanation
Java access modifiers are public, protected, private, and default (package-private). internal is a C# modifier.


16) What is the default value of an object reference variable in Java?

  1. 0
  2. false
  3. null
  4. undefined
Show Answer
Answer: c
Explanation
Object reference fields default to null. Primitive numeric fields default to 0, and boolean fields default to false.


17) Which keyword is used to access members of the parent class?

  1. this
  2. super
  3. parent
  4. base
Show Answer
Answer: b
Explanation
super refers to the immediate parent class and is used to access parent constructors, methods, and fields.


18) What exception is thrown when an array is accessed with an invalid index?

  1. IndexOutOfBoundsException
  2. ArrayIndexOutOfBoundsException
  3. NullPointerException
  4. IllegalArgumentException
Show Answer
Answer: b
Explanation
ArrayIndexOutOfBoundsException is thrown when an array is accessed with an index less than 0 or greater than or equal to the array length.


19) Which operator is used to compare two primitives for equality in Java?

  1. =
  2. ==
  3. equals()
  4. ===
Show Answer
Answer: b
Explanation
== compares primitive values. For objects, == compares references, while equals() can be overridden to compare contents.


20) What is the superclass of all classes in Java?

  1. System
  2. Object
  3. Class
  4. Root
Show Answer
Answer: b
Explanation
java.lang.Object is the root of the Java class hierarchy. Every class directly or indirectly extends Object.


21) Which keyword is used to declare an interface in Java?

  1. interface
  2. implements
  3. abstract class
  4. contract
Show Answer
Answer: a
Explanation
interface is used to declare an interface. A class uses implements to implement it.


22) Can a class implement multiple interfaces in Java?

  1. Yes
  2. No
  3. Only if they are abstract
  4. Only up to two
Show Answer
Answer: a
Explanation
A Java class can implement multiple interfaces, but it can extend only one class.


23) Which method in the Object class is used to check for structural equality?

  1. sameAs()
  2. equals()
  3. compareTo()
  4. isEqual()
Show Answer
Answer: b
Explanation
equals() is used for logical equality and can be overridden. compareTo() is for ordering, not equality.


24) Which loop is guaranteed to execute at least once?

  1. for
  2. while
  3. do-while
  4. foreach
Show Answer
Answer: c
Explanation
A do-while loop checks its condition after executing the body, so the body runs at least once.


25) What is the result of 10 / 4 using integer division in Java?

  1. 2.5
  2. 2
  3. 3
  4. 2.0
Show Answer
Answer: b
Explanation
Integer division truncates the decimal part, so 10 / 4 evaluates to 2.


26) Which of the following classes is immutable in Java?

  1. StringBuilder
  2. StringBuffer
  3. String
  4. ArrayList
Show Answer
Answer: c
Explanation
String is immutable. StringBuilder and StringBuffer are mutable, and ArrayList is a mutable collection.


27) What keyword is used to define a constant method that cannot be overridden?

  1. static
  2. final
  3. abstract
  4. strictfp
Show Answer
Answer: b
Explanation
A final method cannot be overridden by subclasses. A final class cannot be extended.


28) Which keyword is used to invoke a constructor of the current class?

  1. this()
  2. super()
  3. new()
  4. self()
Show Answer
Answer: a
Explanation
this() calls another constructor in the same class. super() calls a parent class constructor.


29) What is the size of a char data type in Java?

  1. 8 bits
  2. 16 bits
  3. 32 bits
  4. 64 bits
Show Answer
Answer: b
Explanation
A char is a 16-bit Unicode character in Java.


30) Which memory area in JVM stores class structures like runtime constant pool, field, and method data?

  1. Stack
  2. Heap
  3. Method Area
  4. Native Method Stack
Show Answer
Answer: c
Explanation
The Method Area stores per-class structures such as the runtime constant pool, field and method data, and method code.


31) Which exception occurs when dividing an integer by zero in Java?

  1. ArithmeticException
  2. NullPointerException
  3. NumberFormatException
  4. IllegalArgumentException
Show Answer
Answer: a
Explanation
Integer division by zero throws ArithmeticException. Floating-point division by zero yields Infinity or NaN.


32) What keyword is used to define a class that cannot be instantiated?

  1. interface
  2. abstract
  3. static
  4. final
Show Answer
Answer: b
Explanation
An abstract class cannot be instantiated directly. It is meant to be subclassed.


33) Which collection class allows duplicate elements in Java?

  1. HashSet
  2. TreeSet
  3. ArrayList
  4. HashMap
Show Answer
Answer: c
Explanation
ArrayList is a List and allows duplicate elements. Set implementations such as HashSet and TreeSet do not allow duplicates.


34) Which collection does NOT allow duplicate keys?

  1. List
  2. Set
  3. Map
  4. Vector
Show Answer
Answer: c
Explanation
A Map stores key-value pairs and does not allow duplicate keys. Values may be duplicated.


35) Which keyword is used to prevent serializing a field in Java?

  1. transient
  2. volatile
  3. static
  4. final
Show Answer
Answer: a
Explanation
transient fields are skipped during serialization and are not persisted.


36) Which thread method is used to start execution of a thread?

  1. run()
  2. execute()
  3. start()
  4. init()
Show Answer
Answer: c
Explanation
start() creates a new thread of execution and then calls run(). Calling run() directly does not create a new thread.


37) Which interface must be implemented to create a thread by passing it to the Thread class?

  1. Callable
  2. Runnable
  3. Process
  4. Executable
Show Answer
Answer: b
Explanation
Runnable defines a single run() method and can be passed to a Thread constructor.


38) What is the default initial capacity of an ArrayList in Java?

  1. 5
  2. 10
  3. 16
  4. 20
Show Answer
Answer: b
Explanation
The default initial capacity of an ArrayList is 10 when it is first created without a specified capacity.


39) What is the output of “Hello”.charAt(1)?

  1. H
  2. e
  3. l
  4. o
Show Answer
Answer: b
Explanation
String indices start at 0, so index 1 returns the second character: e.


40) Which statement is used to exit from a loop prematurely?

  1. continue
  2. return
  3. break
  4. exit
Show Answer
Answer: c
Explanation
break exits the current loop or switch statement immediately.


41) Which statement skips the current iteration of a loop?

  1. break
  2. continue
  3. skip
  4. pass
Show Answer
Answer: b
Explanation
continue skips the remaining statements in the current iteration and proceeds to the next iteration.


42) Which class is synchronized and thread-safe?

  1. ArrayList
  2. HashMap
  3. Vector
  4. StringBuilder
Show Answer
Answer: c
Explanation
Vector methods are synchronized. ArrayList, HashMap, and StringBuilder are not thread-safe by default.


43) Which class is preferred for mutable strings in a non-multithreaded environment?

  1. String
  2. StringBuffer
  3. StringBuilder
  4. StringTokenizer
Show Answer
Answer: c
Explanation
StringBuilder is mutable and faster than StringBuffer because it is not synchronized. Use StringBuffer only when thread safety is required.


44) Which keyword is used to declare a variable that may be modified by different threads asynchronously?

  1. transient
  2. volatile
  3. synchronized
  4. atomic
Show Answer
Answer: b
Explanation
volatile ensures that changes to a variable are visible across threads. It does not provide atomicity.


45) Which block is guaranteed to execute regardless of whether an exception occurs or not?

  1. try
  2. catch
  3. finally
  4. final
Show Answer
Answer: c
Explanation
The finally block executes whether an exception is thrown or not, and even if a return statement is reached.


46) What does garbage collection in Java do?

  1. Cleans up unreferenced objects on the heap
  2. Frees stack memory
  3. Deletes unused class files
  4. Optimizes network calls
Show Answer
Answer: a
Explanation
Garbage collection reclaims heap memory occupied by objects that are no longer reachable by any live thread.


47) What method of Garbage Collector can be suggested to run manually?

  1. Runtime.getRuntime().gc()
  2. System.gc()
  3. Both a and b
  4. None of the above
Show Answer
Answer: c
Explanation
Both System.gc() and Runtime.getRuntime().gc() suggest that the JVM run garbage collection, but neither guarantees it will happen immediately.


48) What is method overriding?

  1. Defining multiple methods in the same class with the same name but different parameters
  2. Redefining a parent class method in a child class with the same signature
  3. Hiding a class member
  4. Converting one data type to another
Show Answer
Answer: b
Explanation
Overriding means a subclass provides a new implementation of a method with the same name and parameter list as a superclass method.


49) What is method overloading?

  1. Methods with the same name and parameter list in different classes
  2. Methods with the same name but different parameter list in the same class
  3. Overriding a static method
  4. Calling a method recursively
Show Answer
Answer: b
Explanation
Overloading means multiple methods in the same class share a name but have different parameter lists.


50) Can static methods be overridden in Java?

  1. Yes
  2. No
  3. Only in abstract classes
  4. Only in interfaces
Show Answer
Answer: b
Explanation
Static methods are resolved at compile time and are hidden, not overridden. Overriding applies to instance methods.


51) What is the return type of a constructor in Java?

  1. void
  2. int
  3. Object
  4. No return type, not even void
Show Answer
Answer: d
Explanation
Constructors have no return type, not even void. If you write void, it becomes a regular method.


52) Which keyword is used to throw an explicit exception?

  1. throws
  2. throw
  3. try
  4. catch
Show Answer
Answer: b
Explanation
throw is used to explicitly throw an exception instance. throws declares exceptions in a method signature.


53) Which keyword is used in a method signature to declare exceptions that the method might throw?

  1. throw
  2. throws
  3. exception
  4. raises
Show Answer
Answer: b
Explanation
throws is used in a method declaration to list checked exceptions that the method may propagate.


54) What type of exception is NullPointerException?

  1. Checked Exception
  2. Unchecked Exception (RuntimeException)
  3. Compile-time Error
  4. Fatal Error
Show Answer
Answer: b
Explanation
NullPointerException is an unchecked exception because it extends RuntimeException.


55) Which exception is a Checked Exception in Java?

  1. IOException
  2. ArithmeticException
  3. IndexOutOfBoundsException
  4. ClassCastException
Show Answer
Answer: a
Explanation
IOException is a checked exception and must be handled or declared. The others are unchecked runtime exceptions.


56) What does the static keyword mean when applied to a field?

  1. The field is constant
  2. The field belongs to the class, not instances
  3. The field is hidden
  4. The field cannot be accessed outside the package
Show Answer
Answer: b
Explanation
A static field is shared by all instances of the class and belongs to the class itself.


57) Which wrapper class corresponds to the float primitive type?

  1. Float
  2. Floating
  3. Double
  4. Real
Show Answer
Answer: a
Explanation
java.lang.Float is the wrapper class for the primitive float type.


58) What is autoboxing in Java?

  1. Converting a primitive type to its corresponding wrapper class automatically
  2. Converting a wrapper class to its primitive type
  3. Casting an object to a subclass
  4. Converting a string to an integer
Show Answer
Answer: a
Explanation
Autoboxing is the automatic conversion of a primitive to its wrapper class, e.g., int to Integer.


59) What is unboxing in Java?

  1. Converting a primitive to a wrapper
  2. Converting a wrapper object to its corresponding primitive type
  3. Unpacking a ZIP file
  4. Parsing a String
Show Answer
Answer: b
Explanation
Unboxing is the automatic conversion of a wrapper object to its primitive type, e.g., Integer to int.


60) Which operator is used to instantiate an object or array?

  1. alloc
  2. new
  3. malloc
  4. create
Show Answer
Answer: b
Explanation
The new operator is used to create objects and arrays in Java.


61) What is the default value of a double variable in Java?

  1. 0
  2. 0.0
  3. 0.0d
  4. Both b and c
Show Answer
Answer: d
Explanation
The default value of a double is 0.0, which is the same as 0.0d.


62) Which method converts a string representation of a number to an integer?

  1. Integer.parseInt()
  2. Integer.valueOf()
  3. int.parse()
  4. Both a and b
Show Answer
Answer: d
Explanation
Integer.parseInt() returns a primitive int, while Integer.valueOf() returns an Integer object. Both can convert a numeric String.


63) Which collection class maintains insertion order?

  1. HashSet
  2. LinkedHashSet
  3. TreeSet
  4. HashMap
Show Answer
Answer: b
Explanation
LinkedHashSet maintains insertion order. HashSet does not guarantee order, and TreeSet sorts elements.


64) Which map class maintains keys in sorted order?

  1. HashMap
  2. LinkedHashMap
  3. TreeMap
  4. Hashtable
Show Answer
Answer: c
Explanation
TreeMap stores keys in sorted order according to their natural ordering or a custom Comparator.


65) What is the scope of a private member of a class?

  1. Within the package
  2. Within the class only
  3. Within subclasses only
  4. Everywhere
Show Answer
Answer: b
Explanation
A private member is accessible only within the class in which it is declared.


66) What is the default access modifier if none is specified?

  1. public
  2. private
  3. protected
  4. package-private (default)
Show Answer
Answer: d
Explanation
If no access modifier is specified, the member has package-private access, meaning it is visible only within the same package.


67) Which feature was introduced in Java 8 to support functional programming?

  1. Generics
  2. Lambda Expressions
  3. Annotations
  4. Enums
Show Answer
Answer: b
Explanation
Lambda expressions were introduced in Java 8 to enable functional programming and simplify the use of functional interfaces.


68) What interface represents a function that takes one argument and produces a result in Java 8?

  1. Supplier
  2. Consumer
  3. Function
  4. Predicate
Show Answer
Answer: c
Explanation
Function<T,R> takes one argument of type T and returns a result of type R.


69) Which functional interface returns a boolean value given an argument?

  1. Function
  2. Consumer
  3. Predicate
  4. Supplier
Show Answer
Answer: c
Explanation
Predicate<T> represents a boolean-valued function that takes one argument.


70) Which functional interface takes no arguments and returns a result?

  1. Supplier
  2. Consumer
  3. Runnable
  4. Function
Show Answer
Answer: a
Explanation
Supplier<T> takes no arguments and returns a result of type T.


71) What does the Stream.filter() method do in Java Streams API?

  1. Transforms elements
  2. Filters elements based on a Predicate
  3. Reduces elements to a single value
  4. Sorts elements
Show Answer
Answer: b
Explanation
filter() returns a stream containing only the elements that match the given Predicate.


72) Which of the following is a terminal operation in Java Streams?

  1. map()
  2. filter()
  3. collect()
  4. sorted()
Show Answer
Answer: c
Explanation
collect() is a terminal operation. map(), filter(), and sorted() are intermediate operations.


73) What is the purpose of Optional class introduced in Java 8?

  1. To optimize performance
  2. To avoid NullPointerExceptions
  3. To represent threads
  4. To handle file operations
Show Answer
Answer: b
Explanation
Optional is a container that may or may not contain a non-null value, helping to avoid NullPointerException.


74) How can you define a default implementation for a method inside an interface (Java 8+)?

  1. Using the default keyword
  2. Using the static keyword
  3. Interfaces cannot have implementation
  4. Both a and b
Show Answer
Answer: d
Explanation
Since Java 8, interfaces can have default methods and static methods with implementations.


75) What is the size of byte primitive type in Java?

  1. 1 byte (8 bits)
  2. 2 bytes (16 bits)
  3. 4 bytes (32 bits)
  4. 8 bytes (64 bits)
Show Answer
Answer: a
Explanation
A byte is an 8-bit signed integer.


76) What is the range of a byte data type in Java?

  1. -128 to 127
  2. -32768 to 32767
  3. 0 to 255
  4. -2147483648 to 2147483647
Show Answer
Answer: a
Explanation
An 8-bit signed byte ranges from -128 to 127.


77) What happens if you try to compile a Java class without a main method?

  1. Compile-time error
  2. It compiles fine, but fails at runtime when executed as a standalone app
  3. Syntax error
  4. Warning
Show Answer
Answer: b
Explanation
A class without a main method compiles successfully. It only fails at runtime if you try to run it as a standalone application.


78) Which statement about static initializer blocks is true?

  1. They execute when an object is instantiated
  2. They execute when the class is loaded by the JVM
  3. They execute after the main method completes
  4. They require manual invocation
Show Answer
Answer: b
Explanation
A static initializer block runs once when the class is first loaded and initialized by the JVM.


79) What is marker interface in Java?

  1. An interface with exactly one abstract method
  2. An interface with no methods or fields
  3. An interface with default methods
  4. An interface marked as final
Show Answer
Answer: b
Explanation
A marker interface is an empty interface used to signal a special behavior to the compiler or JVM, e.g., Serializable.


80) Which of the following is a built-in marker interface in Java?

  1. Serializable
  2. Cloneable
  3. Remote
  4. All of the above
Show Answer
Answer: d
Explanation
Serializable, Cloneable, and Remote are all built-in marker interfaces in Java.


81) What is the default capacity multiplier of an ArrayList when it grows?

  1. Doubles (2x)
  2. 1.5 times
  3. 3 times
  4. Fixed size increase of 10
Show Answer
Answer: b
Explanation
ArrayList grows by approximately 1.5 times its current capacity when it needs more space.


82) Which of the following allows null keys in Java?

  1. Hashtable
  2. ConcurrentHashMap
  3. HashMap
  4. TreeMap
Show Answer
Answer: c
Explanation
HashMap allows one null key and multiple null values. Hashtable and ConcurrentHashMap do not allow null keys.


83) What is the result of “Java”.concat(“SE”)?

  1. Java SE
  2. JavaSE
  3. SEJava
  4. Error
Show Answer
Answer: b
Explanation
concat() joins strings without adding a space, so the result is JavaSE.


84) What is the output of Math.abs(-5.5)?

  1. -5.5
  2. 5.5
  3. 5
  4. -5
Show Answer
Answer: b
Explanation
Math.abs(-5.5) returns the absolute value, which is 5.5.


85) Which class can be used to read input from the console easily?

  1. ConsoleReader
  2. Scanner
  3. InputReader
  4. SystemReader
Show Answer
Answer: b
Explanation
java.util.Scanner is commonly used to read console input easily.


86) Which keyword is used to access package members from another package?

  1. export
  2. import
  3. package
  4. include
Show Answer
Answer: b
Explanation
import is used to bring classes from another package into the current source file.


87) Can an abstract class have constructors in Java?

  1. Yes
  2. No
  3. Only private constructors
  4. Only static constructors
Show Answer
Answer: a
Explanation
Yes, an abstract class can have constructors. They are called when a concrete subclass is instantiated.


88) Can an interface have instance fields in Java?

  1. Yes
  2. No, fields are implicitly public, static, and final
  3. Yes, if marked protected
  4. Yes, using default keyword
Show Answer
Answer: b
Explanation
Interfaces cannot have instance fields. Any fields declared in an interface are implicitly public, static, and final.


89) What is the difference between == and .equals() when comparing String objects?

  1. == checks value, .equals() checks memory address
  2. == checks reference memory address, .equals() checks string content
  3. They are identical
  4. == works for primitives, .equals() causes compile error
Show Answer
Answer: b
Explanation
== compares object references, while .equals() on String compares the actual character content.


90) What is String Pool in Java?

  1. A heap memory area storing String literals for memory reuse
  2. A thread pool handling String operations
  3. A stack area for local string variables
  4. A file cache for strings
Show Answer
Answer: a
Explanation
The String Pool is a special memory area in the heap where String literals are stored and reused.


91) What method is used to manually add a String object to the String Pool?

  1. pool()
  2. intern()
  3. addToPool()
  4. save()
Show Answer
Answer: b
Explanation
intern() returns a canonical representation of the string from the String Pool.


92) What is the bitwise XOR operator in Java?

  1. &
  2. |
  3. ^
  4. ~
Show Answer
Answer: c
Explanation
The ^ operator performs a bitwise XOR (exclusive OR).


93) What is the output of 5 & 3 in Java?

  1. 1
  2. 7
  3. 0
  4. 15
Show Answer
Answer: a
Explanation
5 is 101 and 3 is 011 in binary. Bitwise AND gives 001, which is 1.


94) Which right shift operator preserves the sign bit (arithmetic shift)?

  1. >>
  2. >>>
  3. <<
  4. <<<
Show Answer
Answer: a
Explanation
>> is the signed right shift, which preserves the sign bit. >>> is the unsigned right shift.


95) What is the unsigned right shift operator in Java?

  1. >>
  2. >>>
  3. <<
  4. <<<
Show Answer
Answer: b
Explanation
>>> shifts bits to the right and fills the leftmost bits with zeros, regardless of sign.


96) Which annotation indicates that a method is intended to override a method in a superclass?

  1. @Override
  2. @Overload
  3. @Super
  4. @Inherited
Show Answer
Answer: a
Explanation
@Override tells the compiler that the method is intended to override a superclass method, helping catch errors.


97) What annotation suppresses compiler warnings?

  1. @Deprecated
  2. @SuppressWarnings
  3. @SafeVarargs
  4. @Ignore
Show Answer
Answer: b
Explanation
@SuppressWarnings tells the compiler to suppress specific warnings for the annotated element.


98) Which class is used to measure elapsed time with nanosecond precision?

  1. System.currentTimeMillis()
  2. System.nanoTime()
  3. Date.getTime()
  4. Instant.now()
Show Answer
Answer: b
Explanation
System.nanoTime() returns the current value of the running JVM’s high-resolution time source in nanoseconds.


99) Which enum method returns an array of all defined enum constants?

  1. getValues()
  2. values()
  3. toArray()
  4. list()
Show Answer
Answer: b
Explanation
Every enum has an implicit values() method that returns an array of its constants.


100) What is the result of 1.0 / 0.0 in Java floating-point arithmetic?

  1. Throws ArithmeticException
  2. Double.NaN
  3. Double.POSITIVE_INFINITY
  4. 0.0
Show Answer
Answer: c
Explanation
Floating-point division by zero does not throw an exception. 1.0 / 0.0 evaluates to Double.POSITIVE_INFINITY.
MCQ Tutorial
100 C Programming MCQ (Multiple Choice Questions) with Answers
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment