Sobes.tech
Junior — Middle

Can you list the types of classes used in object-oriented programming?

sobes.tech AI

Answer from AI

In object-oriented programming (using Java as an example), several types of classes can be distinguished:

  • Concrete classes — classes that can be instantiated and contain implementations of methods.
  • Abstract classes — classes that cannot be instantiated directly and may contain both implemented and abstract methods (without implementation). Used to create basic templates.
  • Interfaces — define a set of methods without implementation that must be implemented by classes that implement them.
  • Inner classes — classes declared within other classes, which can be static or non-static.
  • Enums — special classes representing a set of constants.

Example of an abstract class and an interface:

abstract class Animal {
    abstract void makeSound();
}

interface Movable {
    void move();
}

class Dog extends Animal implements Movable {
    void makeSound() {
        System.out.println("Bark");
    }
    public void move() {
        System.out.println("Dog runs");
    }
}