11. What is Method Overriding?
It allows a subclass to provide a specific implementation of a method already defined in its superclass.
Example (Java):
class Animal {
void sound() { System.out.println("Animal sound"); }
}
class Dog extends Animal {
void sound() { System.out.println("Bark"); }
}
12. What is a Constructor?
A constructor is a special method used to initialize objects. It has the same name as the class and no return type.
Runs automatically when an object is created.
13. Types of Constructors:
โข Default Constructor: Takes no parameters.
โข Parameterized Constructor: Takes arguments to set properties.
โข Copy Constructor (C++): Copies data from another object.
14. What is a Destructor?
Used in C++ to clean up memory/resources when an object is destroyed.
In Java,
finalize() was used (deprecated now). Java uses garbage collection instead.15. Difference: Abstract Class vs Interface
| Feature | Abstract Class | Interface |
|---------------|----------------------|------------------------|
| Methods | Can have implemented | Only declarations (till Java 8) |
| Inheritance | One abstract class | Multiple interfaces |
| Use case | Partial abstraction | Full abstraction |
16. Can a Class Inherit Multiple Interfaces?
Yes. Java allows a class to implement multiple interfaces, enabling multiple inheritance of type, without ambiguity.
17. What is the super keyword?
Used to refer to the parent class:
โข Access parentโs constructor:
super()โข Call parent method:
super.methodName()18. What is the this keyword?
Refers to the current class instance. Useful when local and instance variables have the same name.
this.name = name;
19. Difference: == vs .equals() in Java
โข
== compares object references (memory address).โข
.equals() compares the content/values.Use
.equals() to compare strings or objects meaningfully.20. What are Static Members?
Static members belong to the class, not individual objects.
โข static variable: shared across all instances
โข static method: can be called without an object
๐ฌ Double Tap โฅ๏ธ for Part-3