A nested class is a class declared within another class. They are used for logical grouping of classes that are only used in one place, which increases encapsulation and makes the code more readable and maintainable.