Skip to content

Commit fe07e69

Browse files
committed
abstract added
Signed-off-by: Someshdiwan <[email protected]>
1 parent 7d246e0 commit fe07e69

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Section13AbstractClasses/src/abstract.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,19 @@ Abstract classes are designed to be incomplete and serve as a base for other cla
55
They may contain abstract methods, which have no implementation, making it impossible to instantiate them directly.
66

77
However, you can create instances of concrete subclasses that extend the abstract class and provide implementations
8-
for all abstract methods.
8+
for all abstract methods.
9+
10+
11+
What happens if a subclass of an abstract class doesn't implement all the abstract methods?
12+
Ans:
13+
If a subclass of an abstract class doesn't implement all the abstract methods, the subclass itself becomes abstract. This means that the subclass cannot be instantiated either. To create a concrete class, all abstract methods from the superclass must be implemented. If you want to leave some methods unimplemented, you must declare the subclass as abstract as well:
14+
15+
```java
16+
abstract class Shape {
17+
abstract double calculateArea();
18+
}
19+
20+
abstract class Rectangle extends Shape {
21+
// calculateArea() is not implemented, so Rectangle is also abstract
22+
}
23+
```

0 commit comments

Comments
 (0)