Skip to main content

JAVA QUIZZ 2

  1. Static functions can be accessed using null reference.
  • True: Static functions can be accessed via class name or via null reference
  • False

It's been optimized away by the compiler, simply because having an instance of the class is not necessary. The compiler basically replaces csm.method(); by CallingStaticMethod.method();

  1. What is the size of double variable?
  • A - 8 bit
  • B - 16 bit
  • C - 32 bit
  • D - 64 bit The double data type is represented by double-precision 64-bit IEEE 754 floating point.
  1. What is the default value of int variable?
  • A - 0
  • B - 0.0
  • C - null
  • D - not defined

int variable has default value of 0 if defined as an instance/static variable.

  1. Which of the following stands true about default modifier of class members?
  • A - By default, variables, methods and constructors can be accessed by subclass only.

  • B - By default, variables, methods and constructors can be accessed by any class lying in any package.

  • C - By default, variables, methods and constructors can be accessed by any class lying in the same package.

  • D - None of the above.

  1. What is Encapsulation?
  • A - Encapsulation is a technique to define different methods of same type.
  • B - Encapsulation is the ability of an object to take on many forms.
  • C - Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods.
  • D - None of the above.

It is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. Therefore encapsulation is also referred to as data hiding.

  1. What is JIT compiler?
  • A - JIT improves the runtime performance of computer programs based on bytecode.

  • B - JIT is an application development framework.

  • C - JIT is an implementation of the Java Virtual Machine which executes Java programs.

  • D - None of the above.

  1. Method Overriding is an example of
  • A - Static Binding.
  • B - Dynamic Binding.
  • C - Both of the above.
  • D - None of the above.
  1. What is synchronization?
  • A - Synchronization is the capability to control the access of multiple threads to shared resources.

  • B - Synchronization is the process of writing the state of an object to another object.

  • C - Synchronization is the process of writing the state of an object to byte stream.

  • D - None of the above.

Synchronization is the capability to control the access of multiple threads to shared resources. synchronized keyword in java provides locking which ensures mutual exclusive access of shared resource and prevent data race.

  1. Is it necessary that each try block must be followed by a catch block?
  • A - True.

  • B - False.

It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block or a finally block.

  1. When does finally block get executed?
  • A - Always when try block get executed, no matter exception occured or not.

  • B - Always when a method get executed, no matter exception occured or not.

  • C - Always when a try block get executed, if exception do not occur.

  • D - Only when exception occurs in try block code.