Java MCQ's Questions Set 1
Q.1. Which of the following option leads to the portability and security of Java?
- Bytecode is executed by JVM
- The applet makes the Java code secure and portable
- Use of exception handling
- Dynamic binding between objects
Answer:- (1)
The Java programs executed by the JVM that makes the code portable and secure. Because JVM prevents the code from generating its side effects. The Java code is portable, as the same byte code can run on any platform.
Q.2. _____ is used to find and fix bugs in the Java programs.
- JVM
- JRE
- JDK
- JDB
Answer:- (4)
The Java Debugger (JDB or jdb) is a command-line java debugger that debugs the java class. It is a part of the Java Platform Debugger Architecture (JPDA) that helps in the inspections and debugging of a local or remote Java Virtual Machine (JVM).
Q.3. Which of the following is a valid declaration of a char?
- char ch = '\utea';
- char ca = 'tea';
- char cr = \u0223;
- char cc = '\itea';
Answer:- (1)
Q.4. What is the return type of the hashCode() method in the Object class?
- Object
- int
- long
- void
Answer:- (2)
Q.5. Which of the following tool is used to generate API documentation in HTML format from doc comments in source code?
- javap tool
- javaw command
- Javadoc tool
- javah command
Answer:- (3)
Q.6. Which method of the Class.class is used to determine the name of a class represented by the class object as a String?
- getClass()
- intern()
- getName()
- toString()
Answer:- (3)
Q.7. What do you mean by nameless objects?
- An object created by using the new keyword.
- An object of a superclass created in the subclass.
- An object without having any name but having a reference.
- An object that has no reference.
Answer:- (4)
The nameless objects are basically referred to as anonymous objects. The anonymous objects do not have any names. When an object is initialized but is not assigned to any reference variable, it is called an anonymous object.
Q.8. An interface with no fields or methods is known as a ______.
- Runnable Interface
- Marker Interface
- Abstract Interface
- CharSequence Interface
Answer:- (2)
Q.9. Which option is false about the final keyword?
- A final method cannot be overridden in its subclasses.
- A final class cannot be extended.
- A final class cannot extend other classes.
- A final method can be inherited.
Answer:- (3)
Q.10. In java, jar stands for_____.
- Java Archive Runner
- Java Application Resource
- Java Application Runner
- None of the above
Answer:- (4)
jar stands for Java ARchive
Q.11. Which of the given methods are of Object class?
- notify(), wait( long msecs ), and synchronized()
- wait( long msecs ), interrupt(), and notifyAll()
- notify(), notifyAll(), and wait()
- sleep( long msecs ), wait(), and notify()
Answer:- (3)
Q.12. Which of the following is a mutable class in java?
- java.lang.String
- java.lang.Byte
- java.lang.Short
- java.lang.StringBuilder
Answer:- (4)
Q.13. If a thread goes to sleep
- It releases all the locks it has.
- It does not release any locks.
- It releases half of its locks.
- It releases all of its lock except one.
Answer:- (2)
The sleep() method does not release any locks of an object for a specific time or until an interrupt occurs. It leads to the poor performance or deadlock of threads.
Q.14. Which of the following modifiers can be used for a variable so that it can be accessed by any thread or a part of a program?
- global
- transient
- volatile
- default
Answer:- (3)
Q.15. Which of the following is true about inheritance in Java?
- Private methods are final.
- Protected members are accessible within a package and inherited classes outside the package.
- Protected methods are final.
- We cannot override private methods.
Answer:- (1), (2) and (4)
Q.16. What is the use of \w in regex?
- Used for a whitespace character
- Used for a non-whitespace character
- Used for a word character
- Used for a non-word character
Answer:- (3)
Q.17. What is the use of the intern() method?
- It returns the existing string from memory
- It creates a new string in the database
- It modifies the existing string in the database
- None of the above
Answer:- (1)
Q.18. In which memory a String is stored, when we create a string using new operator?
- Stack
- String memory
- Heap memory
- Random storage space
Answer:- (3)
Q.19. What do you mean by chained exceptions in Java?
- Exceptions occurred by the VirtualMachineError
- An exception caused by other exceptions
- Exceptions occur in chains with discarding the debugging information
- None of the above
Answer:- (2)
Q.20. Which of the following is true about the anonymous inner class?
- It has only methods
- Objects can't be created
- It has a fixed class name
- It has no class name
Answer:- (4)
For Java Interview Questions Click here
Technical-MCQs For Placement Preparation
Best Gadgets for Engineers