Try to answer these 800+ Java MCQs and check your understanding of the Java subject. Scroll down and let's begin!
A. an instantiator.
B. a constructor.
C. a destructor.
A. No, it does not compile
B. Yes, but will not run
A. Two
B. Three
C. One
A. Arithmetic comparator "=="
B. Equals Method
C. Both
A. use the myClass property.
B. use the instanceOf operator.
C. use the getClass() method.
A. LocalThread
B. Thread
C. Runnable
D. ThreadLocal
A. stop()
B. sleep(long milliseconds)
C. yield()
D. join()
A. Ensures that each call to a synchronized method is run in a separate thread.
B. Creates a new semaphore to prevent two threads from accessing the method simultaneously.
C. Prevents objects outside the current package from accessing the method.
D. Uses the object's intrinsic lock to prevent two threads from accessing the method simultaneously.
A. They may exist, and they can be transient but not volatile.
B. They cannot exist and the compiler will throw a 'field name is ambiguous' error if you attempt to make them.
C. They may exist, and they can be transient and volatile.
D. They may exist, and they can be volatile but not transient.
E. They may exist, but they must be public, static and final.
A. All of these answers are correct
B. Is not required to implement an interface method.
C. Is not required to override an inherited method in a parent class.
D. Will warn you on compilation if your annotated method signature doesn't match a method in a parent class or interface.
E. Clearly documents the intention to override a method in a parent class or implement a method declared in an interface.
A. creating strings which change considerably.
B. creating strings which only change once.
C. retrieval of all or part of a string but not altering the string.
A. has a circular dependency on 2 or more synchronized objects, causing one of the objects to wait indefinitely.
B. has a for loop or while loop that can never satisfy its condition, causing the loop to run forever and the program to wait indefinitely.
C. has a circular try-catch block, in which the catch results in the catch block being reached again repeatedly, causing the program to run indefinitely.
A. They are not equal
B. They are equal
A. m=5
B. m=3
C. Runtime error
D. Compile error
A. No
B. Yes
A. "depth" must be an int.
B. "submarine" must be a method.
C. "dive" must be a method.
D. "submarine" must be the name of a class.
E. "dive" must be the name of an instance field.
A. There is nothing wrong with this method.
B. static methods cannot return type "int"
C. static methods cannot refer to "this" or "super"
A. ArrayList<String> myList = new ArrayList<String>(10);
B. ArrayList<String> myList = new ArrayList<String>();
C. ArrayList<Integer> myList = new ArrayList<Integer>();
D. ArrayList<Double> myList = new ArrayList<Double>();
E. ArrayList<String> myList = new ArrayList<Integer>();
A. Passed by value
B. Passed by reference
A. the Observer Pattern
B. the Flyweight pattern
C. the Singleton pattern
D. the Factory pattern
A. java.naming.security.credential
B. java.naming.security.authentication
C. java.naming.security.principal
D. All of these
A. myClass::~myClass();
B. You don't need a destructor
C. @Override System.gc(){ }
D. @destructor myClass(){ }
A. No, never
B. Yes, as long as they are public, static and final
A. No
B. Yes
A. which must be serializable so that the state can be stored.
B. which must have a public, no-argument constructor.
C. all of these
D. which must follow standard naming conventions for attributes such as getXxxx.
A. Yes
B. No
A. import pkg
B. Import pkg.*
C. import pkg.*
D. Import pkg
A. a class can implement multiple interface
B. a class can inherit multiple superclass
C. a class can inherit multiple abstract superclass
A. class MyDerived implements MyClass
B. public class MyDerived : MyClass
C. class MyDerived extends MyClass
A. public void static main(String[] args)
B. private void main (String[] args)
C. public static main(String[] args)
D. private static void main(String[] args)
E. public static void main(String[] args)
A. Package
B. package
C. pkg
D. pack
E. Pkg
A. Yes
B. No
A. All of these
B. Within a session, the appropriate sender or publisher or receiver or subscriber objects.
C. A connection object provided by the JMS server (the message broker)
D. Within a connection, one or more sessions, which provide a contest for message sending and receiving
A. processes the java code through the Java Virtual Machine (JVM).
B. processes the java code through the native OS interpreter.
C. process the java code through the interpreter which is pointed to by the CLASSPATH statement.
D. none of these
A. stop; jump
B. stop; continue
C. break; jump
D. break; continue
A. river
B. 6
C. 8
D. Columbia
E. 7
A. |
B. &&
C. &
D. ||
A. MyClass mc = MyClass;
B. MyClass mc = new MyClass;
C. MyClass mc = new MyClass();
D. It can't be done. The constructor of MyClass should be defined as public void MyClass(){/*code*/}
E. MyClass mc = MyClass();
A. throw, take, finally
B. try, catch, end
C. throw, catch, end
D. try, catch, finally
E. throw, catch, do
A. typecasting
B. hardcasting
C. datatyping
A. foo("bar1");
B. foo("bar1", "bar2");
C. All of these.
D. foo("bar1", "bar2", "bar3");
A. Encapsulation
B. Abstraction
C. Inheritance
D. Type casting
A. public static void main(String[] args)
B. public void main(String[] args)
C. public static void main(Collection
D. public static int main(String[] args)
A. gcc compiler
B. system runtime compiler
C. javac compiler
A. protected
B. public
C. all of these
D. private
A. All of these
B. Stop running
C. Start running
D. Self initialize
A. Variables
B. Methods
C. All of these
D. Classes
A. only Microsoft Windows platforms.
B. all platforms.
C. only on UNIX based platforms.
A. get
B. import
C. uses
D. using
E. add
A. public final void main(String arg0, String arg1="default") {}
B. public static void main(String [] args) { }
C. public void main(int argc, String [] argv) {}
D. @Main public void main(int argc, String[] argv) {}