Skip to main content

OOP and Java 8 Interview Questions

Part A: Object-Oriented Programming (OOP) Interview Questions​

Beginner Level OOP Questions (1-15)​

Fundamental OOP Concepts​

  1. What is Object-Oriented Programming?

    • Programming paradigm based on objects containing data and methods
  2. What are the four pillars of OOP?

    • Encapsulation, Inheritance, Polymorphism, Abstraction
  3. What is a class and object?

    • Class: blueprint/template, Object: instance of a class
  4. What is encapsulation? Provide an example.

    • Wrapping data and methods together, hiding internal implementation
    class Person {
    private String name;
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    }
  5. What is inheritance? What are its types?

    • Mechanism to acquire properties of another class
    • Types: Single, Multilevel, Hierarchical, Multiple (through interfaces), Hybrid
  6. What is polymorphism? Explain its types.

    • One interface, multiple implementations
    • Types: Compile-time (method overloading) and Runtime (method overriding)
  7. What is abstraction?

    • Hiding implementation details and showing only essential features
  8. What is the difference between abstraction and encapsulation?

    • Abstraction: hiding complexity, Encapsulation: hiding data
  9. What is method overloading?

    • Same method name with different parameters in same class
  10. What is method overriding?

    • Child class provides specific implementation of parent class method
  11. What is the difference between overloading and overriding?

    • Overloading: compile-time, same class; Overriding: runtime, different classes
  12. What is a constructor? What are its types?

    • Special method to initialize objects
    • Types: Default, Parameterized, Copy constructor
  13. What is constructor overloading?

    • Multiple constructors with different parameters
  14. What is the difference between constructor and method?

    • Constructor initializes object, method performs operations
  15. What is this keyword?

    • Reference to current object instance

Intermediate Level OOP Questions (16-25)​

  1. What is super keyword?

    • Reference to parent class members
  2. What is the difference between this() and super()?

    • this(): calls current class constructor, super(): calls parent constructor
  3. What is an abstract class?

    • Class that cannot be instantiated, can have abstract and concrete methods
  4. What is an interface?

    • Contract defining method signatures, pure abstraction (before Java 8)
  5. What is the difference between abstract class and interface?

    • Abstract class: partial abstraction, Interface: complete abstraction
    • Abstract class: can have constructors, Interface: cannot
  6. Can we have multiple inheritance in Java? How?

    • No through classes, Yes through interfaces
  7. What is composition?

    • "Has-a" relationship, object contains other objects
  8. What is aggregation?

    • Special form of association, "has-a" relationship with independent lifecycle
  9. What is the difference between composition and inheritance?

    • Composition: "has-a", Inheritance: "is-a"
  10. What is association, aggregation, and composition?

    • Association: relationship between classes
    • Aggregation: weak "has-a"
    • Composition: strong "has-a"

Advanced Level OOP Questions (26-30)​

  1. What is dynamic method dispatch?

    • Runtime method resolution based on object type
  2. What is the diamond problem?

    • Ambiguity in multiple inheritance, solved by interfaces in Java
  3. What is SOLID principles?

    • Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
  4. What are design patterns? Name few important ones.

    • Reusable solutions to common problems
    • Singleton, Factory, Observer, Strategy, Decorator
  5. What is tight coupling and loose coupling?

    • Tight: high dependency, Loose: low dependency between classes

Part B: Java 8 Interview Questions​

Beginner Level Java 8 Questions (1-15)​

Lambda Expressions​

  1. What are the new features introduced in Java 8?

    • Lambda expressions, Stream API, Functional interfaces, Optional, Method references, Default methods
  2. What is a lambda expression?

    • Anonymous function that can be treated as a value
    (parameters) -> expression
    (parameters) -> { statements; }
  3. What is a functional interface?

    • Interface with exactly one abstract method (SAM - Single Abstract Method)
  4. What is @FunctionalInterface annotation?

    • Ensures interface has only one abstract method
  5. What are the built-in functional interfaces in Java 8?

    • Predicate, Function, Consumer, Supplier, UnaryOperator, BinaryOperator
  6. What is Predicate functional interface?

    • Takes one argument, returns boolean
    Predicate<String> isEmpty = s -> s.isEmpty();
  7. What is Function functional interface?

    • Takes one argument, returns a result
    Function<String, Integer> length = s -> s.length();
  8. What is Consumer functional interface?

    • Takes one argument, returns nothing (void)
    Consumer<String> print = s -> System.out.println(s);
  9. What is Supplier functional interface?

    • Takes no argument, returns a result
    Supplier<String> supplier = () -> "Hello World";
  10. What are method references?

    • Shorthand notation for lambda expressions
    • Types: Static, Instance, Constructor, Instance of arbitrary object
  11. What are the types of method references?

    • Static: Class::staticMethod
    • Instance: object::instanceMethod
    • Constructor: Class::new
    • Instance of arbitrary object: Class::instanceMethod
  12. What is the difference between lambda expression and method reference?

    • Method reference is shorthand for lambda when calling existing method
  13. Can we use lambda expressions with any interface?

    • No, only with functional interfaces
  14. What is the difference between lambda and anonymous inner class?

    • Lambda: functional interfaces only, Anonymous class: any interface/abstract class
  15. What are default methods in interfaces?

    • Methods with implementation in interfaces (Java 8+)

Intermediate Level Java 8 Questions (16-30)​

Stream API​

  1. What is Stream API?

    • Functional-style operations on collections of objects
  2. What are the characteristics of Stream?

    • No storage, Functional, Lazy evaluation, Possibly unbounded, Consumable
  3. What is the difference between Collection and Stream?

    • Collection: data structure, Stream: abstraction for processing data
  4. What are intermediate and terminal operations in Stream?

    • Intermediate: return Stream (filter, map, sorted)
    • Terminal: return non-Stream result (collect, forEach, reduce)
  5. What is the difference between map() and flatMap()?

    • map(): one-to-one mapping
    • flatMap(): one-to-many mapping, flattens nested structures
  6. What is filter() method in Stream?

    • Filters elements based on predicate
    list.stream().filter(x -> x > 5).collect(toList());
  7. What is collect() method in Stream?

    • Terminal operation to transform stream elements into different form
  8. What are Collectors?

    • Utility class with predefined collectors (toList, toSet, groupingBy, etc.)
  9. What is reduce() method?

    • Combines stream elements into single result
    Optional<Integer> sum = numbers.stream().reduce(Integer::sum);
  10. What is the difference between findFirst() and findAny()?

    • findFirst(): returns first element, findAny(): returns any element
  11. What is parallel stream?

    • Stream that can be processed in parallel across multiple threads
    list.parallelStream().filter(predicate);
  12. When should you use parallel streams?

    • Large datasets, CPU-intensive operations, independent operations
  13. What is Optional class?

    • Container object to handle null values gracefully
  14. What are the methods of Optional class?

    • of(), ofNullable(), empty(), isPresent(), ifPresent(), orElse(), orElseGet()
  15. What is the difference between orElse() and orElseGet()?

    • orElse(): always executes, orElseGet(): executes only if empty

Advanced Level Java 8 Questions (31-40)​

Advanced Features​

  1. What are static methods in interfaces?

    • Methods that belong to interface, not implementing class
  2. What is the diamond problem with default methods?

    • Multiple interfaces with same default method, resolved by implementing class
  3. How do you resolve conflicts with multiple default methods?

    • Override in implementing class or use Interface.super.method()
  4. What is CompletableFuture?

    • Enhanced Future for asynchronous programming
  5. What are the differences between Future and CompletableFuture?

    • CompletableFuture: composable, chainable, better exception handling
  6. What is Date and Time API in Java 8?

    • New immutable date-time classes: LocalDate, LocalTime, LocalDateTime, ZonedDateTime
  7. What are the advantages of new Date-Time API?

    • Immutable, Thread-safe, Clear API, Better parsing/formatting
  8. What is forEach() method?

    • Internal iteration method for collections and streams
  9. What is the difference between external and internal iteration?

    • External: for loop (imperative), Internal: forEach (functional)
  10. What are StringJoiner and String.join()?

    • Utilities for joining strings with delimiters

Common Coding Examples​

OOP Example:​

// Encapsulation + Inheritance + Polymorphism
abstract class Animal {
protected String name;

public Animal(String name) { this.name = name; }

public abstract void makeSound();

public void sleep() { System.out.println(name + " is sleeping"); }
}

class Dog extends Animal {
public Dog(String name) { super(name); }

@Override
public void makeSound() { System.out.println(name + " barks"); }
}

Java 8 Example:​

// Lambda + Stream + Optional
List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "David");

Optional<String> result = names.stream()
.filter(name -> name.startsWith("C"))
.map(String::toUpperCase)
.findFirst();

result.ifPresent(System.out::println); // CHARLIE

Interview Preparation Tips:​

For OOP Questions:​

  • Practice implementing all four pillars with code examples
  • Understand real-world scenarios where each concept applies
  • Be ready to draw UML diagrams
  • Know design patterns and SOLID principles

For Java 8 Questions:​

  • Practice writing lambda expressions and method references
  • Master Stream API operations with examples
  • Understand functional programming concepts
  • Practice converting imperative code to functional style

Common Follow-up Areas:​

  • Performance implications
  • Best practices and when to use what
  • Real-world application scenarios
  • Code optimization techniques