All Flashcards
What is the difference between using 'super' to call a constructor vs. calling a method?
Constructor: initializes the object's state | Method: executes a specific action or behavior.
What is the difference between overriding a method and overloading a method?
Overriding: Providing a new implementation in a subclass | Overloading: Providing multiple methods with the same name but different parameters in the same class.
What is the difference between inheritance and composition?
Inheritance: A class acquires properties from a parent class | Composition: A class contains instances of other classes as its members.
What is the difference between using 'super' and 'this'?
'super': Refers to the superclass | 'this': Refers to the current instance of the class.
What are the key differences between a superclass and a subclass?
Superclass: More general, provides base functionality | Subclass: More specific, extends or modifies superclass functionality.
What is the difference between abstract and concrete classes?
Abstract: Cannot be instantiated, may contain abstract methods | Concrete: Can be instantiated, provides implementations for all methods.
What is the difference between public and private access modifiers?
Public: Accessible from anywhere | Private: Accessible only within the class.
What is the difference between compile-time and runtime?
Compile-time: When the code is translated into machine code | Runtime: When the code is executed.
What is the difference between procedural and object-oriented programming?
Procedural: Code is organized into functions | Object-oriented: Code is organized into objects with data and methods.
What is the difference between a class and an object?
Class: Blueprint for creating objects | Object: Instance of a class.
Why use 'super' for methods?
To reuse the superclass's implementation of a method in a subclass, avoiding code duplication.
What's the benefit of avoiding code duplication?
Reduces maintenance effort, improves code readability, and minimizes potential errors.
How does 'super' relate to inheritance?
It allows a subclass to access and utilize the inherited methods and constructors of its superclass.
When should you override a method?
When a subclass needs to provide a specific implementation that differs from the superclass's implementation.
What is the purpose of the @Override annotation?
It indicates that a method is overridden, allowing the compiler to check for errors.
Why is code reusability important?
It saves time and resources by leveraging existing code instead of rewriting it.
Explain the relationship between a subclass and its superclass.
A subclass inherits properties and behaviors from its superclass, allowing it to extend or modify the superclass's functionality.
What is the role of a constructor in object creation?
A constructor initializes the object's state by setting initial values for its attributes.
How does 'super' promote code maintainability?
By centralizing common logic in the superclass and allowing subclasses to build upon it, changes in the superclass automatically propagate to subclasses.
What is the significance of the 'is-a' relationship in inheritance?
It represents that a subclass is a specialized type of its superclass, inheriting its characteristics and behaviors.
What is the 'super' keyword?
A keyword used to invoke the superclass's constructor or methods from within a subclass.
What is inheritance?
A mechanism where a class inherits properties and methods from another class (superclass).
What is method overriding?
When a subclass provides a specific implementation for a method that is already defined in its superclass.
What is a superclass?
The class whose properties are inherited by another class (subclass).
What is a subclass?
A class that inherits properties and methods from another class (superclass).
What is code duplication?
Repeating the same code in multiple places, which can lead to maintenance issues.
What is method overloading?
Defining multiple methods in the same class with the same name but different parameters.
What is an implementation?
The actual code that defines how a method or class behaves.
What is a constructor?
A special method used to initialize objects of a class.
What does 'invoke' mean in programming?
To call or execute a method or function.