Sobes.tech
Intern

What capabilities does a subclass provide in object-oriented programming?

sobes.tech AI

Answer from AI

  1. Inheritance of properties and methods: The subclass gains access to the public and protected members of the base class.
  2. Overriding: Allows changing the implementation of base class methods.
  3. Adding new properties and methods: The subclass can extend functionality by adding its own members.
  4. Polymorphism: The ability to treat an object of the subclass as an object of the base class.

Example of method overriding:

class Animal {
    void makeSound() {
        // Emits a general sound
    }
}

class Dog extends Animal {
    @Override
    void makeSound() {
        // Emits a dog's sound
    }
}