Abstraction Assignment
Abstraction Assignment
the necessary parts of an object. Abstraction is achieved in Java using abstract classes and
of an object, abstraction reduces complexity and improves the manageability of code. This
software architecture where only relevant details are shared with the user.
1. Abstract Class:
- Suitable when there is a need to provide a base class with default behavior.
2. Interface:
- Contains only abstract methods (Java 8 and later allows default and static methods).
- Best used when defining a contract that multiple classes should adhere to.
Example:
```java
abstract class Animal {
void sleep() {
System.out.println("Sleeping...");
interface Movable {
void move();
```
1. Upcasting:
- Example:
```java
```
- Dynamic Method Dispatch, also known as runtime polymorphism, is the mechanism in Java
- Example:
```java
```
In the example, even though `animal` is of type `Animal`, the method `sound()` in `Dog` is