Govt Exams
An abstract class can have zero or more abstract methods. It can also have concrete methods, constructors, and instance variables.
A final method cannot be overridden. Attempting to override it results in a compilation error: 'cannot override final method'.
Method overloading requires different parameter types or number of parameters. Options A and D have different return types (not valid for overloading), and option B has the same signature with different parameter names (not overloading).
Composition (HAS-A relationship) is often preferred over inheritance (IS-A relationship) because it's more flexible and avoids tight coupling.
Default methods in interfaces (Java 8+) provide a default implementation. Implementing classes can use this default implementation or override it as needed.
From Java 8, interfaces can have default and static methods, but abstract classes can have instance variables, constructors, and private methods which interfaces cannot have.
If a parent class has a parameterized constructor and no default constructor, the child class must explicitly call it using super() to initialize parent class members.
'this' is a reference to the current object instance, while 'super' is a reference to the parent class. They serve different purposes in inheritance hierarchy.
The 'final' keyword when applied to a variable makes it a constant. When applied to a class, it cannot be extended. When applied to a method, it cannot be overridden.
class Parent { void show() { System.out.println("Parent"); } }
class Child extends Parent { void show() { System.out.println("Child"); } }
public class Test { public static void main(String[] args) { Parent p = new Child(); p.show(); } }
This demonstrates runtime polymorphism. Although the reference is of type Parent, the actual object is Child. The overridden show() method in Child class is executed.