Interview Q&A / Java

INTERVIEW Q&A · 72 QUESTIONS

Java interview questions

Collections, the JVM, strings, exceptions and threads, the backbone of most campus placement rounds.

  1. What does the static keyword mean in Java?

    static means a member belongs to the class itself, not to any one object. A static variable has one shared copy, a static method can be called without creating an object, a static block runs once when the class is loaded, and a static nested class does not need an outer object.

    IntermediateIn-depth3 min read
  2. In what order do static blocks, instance blocks and constructors run in Java?

    A static block runs once when the class is first loaded. For every new object, instance initialiser blocks and field initialisers run first, in source order, and then the constructor body.

    IntermediateQuick answer1 min read
  3. What is a blank final variable in Java and how do you initialise it?

    A blank final is a final field declared without a value. It must be assigned exactly once, in every constructor for an instance field or in a static block for a static one, otherwise the code does not compile.

    IntermediateQuick answer1 min read
  4. What is the difference between a static nested class and an inner class in Java?

    An inner (non-static) class holds a hidden reference to an instance of its outer class and can use its members. A static nested class has no such link, so it can be created without an outer object, like an ordinary top-level class placed inside another for organisation.

    IntermediateQuick answer1 min read