- Which provides a runtime environment for Java byte code to be executed?
- a. JDK
- b. JVM
- c. JRE
- d. JAVAC
- Answer: b. JVM
- Which of the following are not Java keywords?
- a. double
- b. switch
- c. then
- d. instanceof
- Answer: c. then
- The default value of a static integer variable of a class in Java is,
- a. 0
- b. 1
- c. Garbage value
- d. Null
- Answer: a. 0
- Multiple inheritance means,
- a. one class inheriting from more superclasses
- b. more classes inheriting from one superclass
- c. more classes inheriting from more super classes
- d. None of the above
- Answer: a. one class inheriting from more superclasses
- Which statement is not true in the Java language?
- a. A public member of a class can be accessed in all the packages.
- b. A private member of a class cannot be accessed by the methods of the same class.
- c. A private member of a class cannot be accessed from its derived class.
- d. A protected member of a class can be accessed from its derived class.
- Answer: b. A private member of a class cannot be accessed by the methods of the same class (False).
- To prevent any method from overriding, we declare the method as,
- a. static
- b. const
- c. final
- d. abstract
- Answer: c. final
- Which one of the following is not true?
- a. A class containing abstract methods is called an abstract class.
- b. Abstract methods should be implemented in the derived class.
- c. An abstract class cannot have non-abstract methods.
- d. A class must be qualified as an ‘abstract’ class if it contains one abstract method.
- Answer: c. An abstract class cannot have non-abstract methods (False).
- The fields in an interface are implicitly specified as,
- a. static only
- b. protected
- c. private
- d. both static and final
- Answer: d. both static and final
- Which of the following is true?
- a. A finally block is executed before the catch block but after the try block.
- b. A finally block is executed, only after the catch block is executed.
- c. A finally block is executed whether an exception is thrown or not.
- d. A finally block is executed, only if an exception occurs.
- Answer: c. A finally block is executed whether an exception is thrown or not.
- What is garbage collection in the context of Java?
- a. The operating system periodically deletes all the Java files available on the system.
- b. Any package imported in a program and not used is automatically deleted.
- c. When all references to an object are gone, the memory used by the object is automatically reclaimed.
- d. The JVM checks the output of any Java program and deletes anything that doesn’t make sense.
- Answer: c. When all references to an object are gone, the memory used by the object is automatically reclaimed.
- The Java runtime system automatically calls this method while garbage collection.
- a. finalizer()
- b. finalize()
- c. finally()
- d. finalized()
- Answer: b. finalize()
- The correct order of the declarations in a Java program is,
- a. Package declaration, import statement, class declaration
- b. The import statement, package declaration, the class declaration
- c. Import statement, class declaration, package declaration
- d. Class declaration, import statement, package declaration
- Answer: a. Package declaration, import statement, class declaration
- An overloaded method consists of,
- a. The same method name with different types of parameters
- b. The same method name with different number of parameters
- c. The same method name and same number and type of parameters with different return type
- d. Both (a) and (b) above
- Answer: d. Both (a) and (b) above
- A protected member can be accessed in, Which is the false option?
- a. a subclass of the same package
- b. non-subclass of the same package
- c. a non-subclass of different package
- d. a subclass of different package
- Answer: b. non-subclass of the same package (False).
- All exception types are subclasses of the built-in class
- a. Exception
- b. RuntimeException
- c. Error
- d. Throwable
- Answer: d. Throwable
- When an overridden method is called from within a subclass, it will always refer to the version of that method defined by the
- a. Super class
- b. Subclass
- c. Compiler will choose randomly
- d. Interpreter will choose randomly
- Answer: b. Subclass
- Java compiler
javac translates Java source code into
- In Java, a character constant’s value is its integer value in the
- In Java, a try block should immediately be followed by one or more .................... blocks.
- An abstract data type typically comprises a ............... and a set of .................. respectively.