All fields

“OOP & Classes” in Information Technology

98 questions across 6 technologies.

Information Technology

98 questions in 6 technologies

#QuestionTechnologyTopicLevel
1How would you use an abstract class to implement the Template Method pattern, defining a fixed algorithm skeleton with some steps left abstract for subclasses to fill in? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesIntermediate
2Can an interface extend multiple other interfaces simultaneously, and how does this differ from a class's single-inheritance restriction for abstract/concrete classes? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesIntermediate
3How do local classes (defined within a method body) and anonymous classes differ in their capabilities and use cases, particularly regarding capturing local variables and reusability? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesAdvanced
4How does the compiler implement inner classes at the bytecode level, and what synthetic elements (like a hidden outer-class reference field and synthetic accessor methods) does it generate to make this work? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesAdvanced
5How would you use an anonymous class to create a one-off subclass with a customized implementation, distinct from anonymous classes implementing an interface, and what specific syntax quirk applies? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesAdvanced
6What is an interface in PHP, and what purpose does it serve in defining a contract for classes to follow? PHP › Interfaces & Abstract ClassesPHPInterfaces & Abstract ClassesBeginner
7How do you decide whether to use an interface or an abstract class when designing a set of related classes that share common behavior? PHP › Interfaces & Abstract ClassesPHPInterfaces & Abstract ClassesIntermediate
8How does PHP's type system use interfaces to enable polymorphism, allowing different concrete classes to be used interchangeably wherever the interface type is expected? PHP › Interfaces & Abstract ClassesPHPInterfaces & Abstract ClassesIntermediate
9How does the 'sealed' modifier interact with abstract classes and interface method overrides to control further extensibility? C# › Interfaces & Abstract ClassesC#Interfaces & Abstract ClassesAdvanced
10How would you implement inheritance between dataclasses, and what field-ordering rule must be respected across the hierarchy? Python › Dataclasses & NamedTuplesPythonDataclasses & NamedTuplesAdvanced
11How does the Liskov Substitution Principle relate to properly designing interfaces and abstract classes so that subclasses can genuinely be substituted for their parent type without breaking expected behavior? PHP › Interfaces & Abstract ClassesPHPInterfaces & Abstract ClassesAdvanced
12What is a non-static (inner) class in Java, and how does its relationship to an enclosing instance differ from a regular top-level class? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesBeginner
13How do you instantiate a non-static inner class from OUTSIDE the enclosing class (from a different class entirely), and what is the exact syntax required? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesBeginner
14What is the fundamental difference between an interface and an abstract class in Java, and when would you choose one over the other? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesBeginner
15Can an interface declare instance fields, and if so, what implicit modifiers are automatically applied to any field declared in an interface? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesBeginner
16What is the difference between an interface and an abstract class in C#, and when should you choose one over the other? C# › Interfaces & Abstract ClassesC#Interfaces & Abstract ClassesBeginner
17How does a local or anonymous class defined inside a static method or static context differ from one defined inside an instance method, regarding what enclosing state it can access? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesIntermediate
18Can a local class or anonymous class be generic, and how does its own type parameter interact with any generic type parameters already declared on its enclosing class or method? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesIntermediate
19How would you access the enclosing outer class's instance from within a nested inner class when there's a naming conflict (like a shadowed field with the same name), using the OuterClassName.this syntax? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesIntermediate
20How do default methods (introduced in Java 8) let an interface provide a method implementation, and what problem were they specifically introduced to solve? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesIntermediate
21What is the purpose of declaring an abstract class with a protected constructor, and how does this pattern communicate the class's intended usage to other developers? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesIntermediate
22How would you implement the 'mixin' pattern in Java using default methods on an interface, letting a class gain reusable behavior without traditional inheritance? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesIntermediate
23How would you use an abstract class's constructor to enforce that certain validation or initialization logic always runs for every subclass, something an interface (lacking constructors entirely) cannot provide? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesIntermediate
24How would you decide between using a static nested class, a non-static inner class, a local class, an anonymous class, or a lambda expression for a given design scenario, weighing their respective trade-offs? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesAdvanced
25How is the 'diamond problem' (a class implementing two interfaces with conflicting default methods) resolved in Java, and what rule determines which default method 'wins' or whether the compiler requires explicit resolution? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesAdvanced
26What are private methods on an interface (introduced in Java 9), and what specific problem do they solve regarding code duplication between multiple default methods? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesAdvanced
27What is an interface, and what can (and can't) it contain in its most basic form? C# › Interfaces & Abstract ClassesC#Interfaces & Abstract ClassesBeginner
28What is the default behavior of equals() and hashCode() inherited from Object, and why is it usually necessary to override them for value-based classes? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsBeginner
29What is the Iterator interface in PHP, and how does it relate to how a foreach loop actually works behind the scenes? PHP › Generators & IteratorsPHPGenerators & IteratorsBeginner
30What is an abstract class in PHP, and how does it differ from a regular class and from an interface? PHP › Interfaces & Abstract ClassesPHPInterfaces & Abstract ClassesBeginner
31What are the four core principles of object oriented programming, and how does PHP support each of them? PHP › OOPPHPOOPBeginner
32What are the three visibility modifiers in PHP, public, protected, and private, and how do they control access to a class's properties and methods? PHP › OOPPHPOOPBeginner
33What is a trait in PHP, and how does it let you share a set of methods across multiple unrelated classes without using traditional inheritance? PHP › TraitsPHPTraitsBeginner
34How do you decide between using an interface versus an abstract class for a given design? C# › Interfaces & Abstract ClassesC#Interfaces & Abstract ClassesIntermediate
35How does explicit interface implementation work, and when would you use it instead of a normal (implicit) implementation? C# › Interfaces & Abstract ClassesC#Interfaces & Abstract ClassesIntermediate
36What is the Template Method pattern, and how is it used to define the skeleton of an algorithm while letting subclasses customize specific steps? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
37Can an interface extend another interface in PHP, and how does this let you build more specific contracts on top of a more general one? PHP › Interfaces & Abstract ClassesPHPInterfaces & Abstract ClassesIntermediate
38How does inheritance work in PHP using the extends keyword, and how do you call a parent class's constructor or method from within a child class? PHP › OOPPHPOOPIntermediate
39Can constexpr be used with classes and containers? C++ › Constexpr & Compile-TimeC++Constexpr & Compile-TimeAdvanced
40How does the getClass() versus instanceof choice in an equals() implementation affect whether subclasses can be considered equal to their superclass instances, and what's the Liskov Substitution Principle tension involved? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsAdvanced
41How would you correctly implement equals() and hashCode() for a class in an inheritance hierarchy where the superclass itself defines meaningful equality-relevant fields, without breaking the contract when subclasses add their own fields? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsAdvanced
42How would you design a custom exception hierarchy for an application, deciding when to create new exception classes versus reusing existing ones, and what fields/context should a well-designed custom exception carry? Java › ExceptionsJavaExceptionsAdvanced
43How does PHP handle multiple inheritance limitations, and how do traits provide a mechanism for sharing reusable code across multiple unrelated class hierarchies? PHP › OOPPHPOOPAdvanced
44What is a service container, and what problem does it solve when an application has many interdependent classes? PHP › Dependency Injection & Service ContainersPHPDependency Injection & Service ContainersBeginner
45Why would a developer choose to use a trait instead of simply duplicating the same method directly into multiple different classes? PHP › TraitsPHPTraitsBeginner
46How do custom exception classes work in C#, and what's the recommended convention for creating one? C# › Exception HandlingC#Exception HandlingIntermediate
47How do trait properties and static properties behave when a trait is used by multiple different classes, and is that state actually shared between them? PHP › TraitsPHPTraitsIntermediate
48How does the dependency inversion principle relate to dependency injection, and how does designing around abstractions rather than concrete classes improve long term maintainability? PHP › Dependency Injection & Service ContainersPHPDependency Injection & Service ContainersAdvanced
49What is a const member function? C++ › Const CorrectnessC++Const CorrectnessBeginner
50What are the four C++ named casts? C++ › Casting & ConversionsC++Casting & ConversionsBeginner
51What is the difference between implicit and explicit conversions? C++ › Casting & ConversionsC++Casting & ConversionsBeginner
52What do the built-in @Override, @Deprecated, and @SuppressWarnings annotations do? Java › AnnotationsJavaAnnotationsBeginner
53How do you apply multiple different annotations to the same element, and does their order matter? Java › AnnotationsJavaAnnotationsBeginner
54What is the Singleton pattern, and how would you implement a thread-safe Singleton in Java? Java › Design Patterns in JavaJavaDesign Patterns in JavaBeginner
55What is the Factory Method pattern's simplest form -- a basic static factory returning different subtype instances based on input -- and why might you prefer it over exposing constructors directly? Java › Design Patterns in JavaJavaDesign Patterns in JavaBeginner
56What is an enum in Java, and how does it differ from simply using a set of integer or String constants? Java › EnumsJavaEnumsBeginner
57What is the difference between the == operator and the .equals() method when comparing two custom objects, if the class hasn't overridden equals()? Java › Java Fundamentals: Syntax, Data Types & OperatorsJavaJava Fundamentals: Syntax, Data Types & OperatorsBeginner
58How do you name a Java module, and what naming convention is recommended to avoid conflicts with other modules? Java › Java Platform Module System (JPMS)JavaJava Platform Module System (JPMS)Beginner
59What is the mutable keyword? C++ › Const CorrectnessC++Const CorrectnessIntermediate
60Why is const correctness important in API design? C++ › Const CorrectnessC++Const CorrectnessIntermediate
61What is dynamic_cast and when do you use it? C++ › Casting & ConversionsC++Casting & ConversionsIntermediate
62What is the explicit keyword and why use it? C++ › Casting & ConversionsC++Casting & ConversionsIntermediate
63What are Java's meta-annotations (@Retention, @Target, @Documented, @Inherited), and what does each control? Java › AnnotationsJavaAnnotationsIntermediate
64How does the Builder pattern solve the "telescoping constructor" problem, and how would you implement it for a class with many optional parameters? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
65What is the Factory Method pattern, and how does it differ from the simpler Static Factory Method idiom (like List.of() or Optional.of())? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
66What is the Adapter pattern, and when would you use it to make an existing class compatible with an interface it wasn't originally designed to implement? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
67What is the difference between composition and inheritance as ways to reuse code, and why does the design principle "favor composition over inheritance" generally guide modern Java design (including many design patterns themselves)? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
68How would you implement the Composite pattern to treat individual objects and groups of objects uniformly, such as a file system with files and directories? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
69How do you add fields, constructors, and methods to a Java enum, and how would you implement an enum representing planets with mass and radius that calculates surface gravity? Java › EnumsJavaEnumsIntermediate
70Why is it particularly important for a class's equals() and hashCode() to be based on effectively immutable data specifically when that class is used as a JPA/Hibernate entity, and what special considerations apply to entity identity before it's persisted (has a generated ID)? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsIntermediate
71How do you create and throw a custom exception class, and what constructors should a well-designed custom exception typically provide? Java › ExceptionsJavaExceptionsIntermediate
72What are the four kinds of method references in Java (static, instance-bound, instance-unbound, and constructor), and how does the compiler determine which form applies? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesIntermediate
73What is an unbounded wildcard (List<?>), and when is it more appropriate to use than a bounded generic method with a type parameter <T>? Java › GenericsJavaGenericsIntermediate
74How does Java's operator precedence and associativity determine the evaluation order of a complex expression, and what are some common precedence-related mistakes? Java › Java Fundamentals: Syntax, Data Types & OperatorsJavaJava Fundamentals: Syntax, Data Types & OperatorsIntermediate
75What is the difference between a Java text block (introduced as a standard feature in Java 15) and a traditional String literal, and what specific syntax rules govern indentation handling? Java › Java Fundamentals: Syntax, Data Types & OperatorsJavaJava Fundamentals: Syntax, Data Types & OperatorsIntermediate
76What is the difference between the ++ (increment) and -- (decrement) operators used in prefix versus postfix position, and what subtle bug can arise from using them within a complex expression? Java › Java Fundamentals: Syntax, Data Types & OperatorsJavaJava Fundamentals: Syntax, Data Types & OperatorsIntermediate
77How does Java's short-circuit evaluation for && and || operators differ from the non-short-circuiting & and | operators when applied to boolean operands, and why does this distinction matter for avoiding NullPointerException? Java › Java Fundamentals: Syntax, Data Types & OperatorsJavaJava Fundamentals: Syntax, Data Types & OperatorsIntermediate
78What is the difference between an instance initializer block and a static initializer block, and when does each execute relative to a class's constructors? Java › Java Fundamentals: Syntax, Data Types & OperatorsJavaJava Fundamentals: Syntax, Data Types & OperatorsIntermediate
79How do the requires and exports directives in a module-info.java file work together to define a module's dependencies and public API surface? Java › Java Platform Module System (JPMS)JavaJava Platform Module System (JPMS)Intermediate
80What is a qualified export (exports package to specificModule), and when would you use it instead of a plain, unqualified export? Java › Java Platform Module System (JPMS)JavaJava Platform Module System (JPMS)Intermediate
81What is the Module pattern in Node.js, and how does it enable encapsulation? Node.js › Architecture & Design PatternsNode.jsArchitecture & Design PatternsIntermediate
82What is the IteratorAggregate interface, and how does it provide a simpler alternative to implementing the full Iterator interface directly? PHP › Generators & IteratorsPHPGenerators & IteratorsIntermediate
83Can a trait define abstract methods, and how does this let a trait enforce that any class using it must provide its own specific implementation of certain behavior? PHP › TraitsPHPTraitsIntermediate
84What is the difference between shallow copy and deep copy in memory terms? C++ › Memory ManagementC++Memory ManagementAdvanced
85What is memory alignment and why does it matter? C++ › Memory ManagementC++Memory ManagementAdvanced
86How are lambdas implemented under the hood? C++ › Lambda ExpressionsC++Lambda ExpressionsAdvanced
87What is the difference between physical and logical constness? C++ › Const CorrectnessC++Const CorrectnessAdvanced
88How do you overload a member function on const? C++ › Const CorrectnessC++Const CorrectnessAdvanced
89What is the difference between static_cast and dynamic_cast for downcasting? C++ › Casting & ConversionsC++Casting & ConversionsAdvanced
90How do repeatable annotations work in Java (using @Repeatable), and what problem do they solve? Java › AnnotationsJavaAnnotationsAdvanced
91How would you implement the Decorator pattern in Java, and how does java.io's InputStream/OutputStream class hierarchy exemplify this pattern in the JDK itself? Java › Design Patterns in JavaJavaDesign Patterns in JavaAdvanced
92How would you implement equals()/hashCode() correctly for a class containing a mutable field, and why does using such a class as a HashMap key or HashSet element create a serious risk? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsAdvanced
93How does Java's type inference determine the target type for a lambda expression in an ambiguous overload scenario, and what happens when a lambda could match multiple overloaded methods accepting different functional interfaces? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesAdvanced
94How do bounded wildcards (? extends T and ? super T) work, and what does the PECS (Producer Extends, Consumer Super) mnemonic mean for choosing between them? Java › GenericsJavaGenericsAdvanced
95How does generic method overload resolution interact with type erasure to sometimes produce a compile error for seemingly valid overloads (like two methods differing only by their generic type parameter)? Java › GenericsJavaGenericsAdvanced
96How would you implement a generic builder pattern with a self-referential generic type parameter (the 'curiously recurring generic pattern', <T extends Builder<T>>) to support fluent method chaining that correctly returns the actual subclass type in an inheritance hierarchy? Java › GenericsJavaGenericsAdvanced
97What is Domain-Driven Design (DDD), and how do its concepts of entities, value objects, and aggregates apply to a Node.js codebase? Node.js › Architecture & Design PatternsNode.jsArchitecture & Design PatternsAdvanced
98How does PHP's type variance, specifically covariance and contravariance, affect how return types and parameter types can be safely changed when overriding a method in a child class? PHP › Type Declarations & Strict TypesPHPType Declarations & Strict TypesAdvanced