Intern
All classes in Kotlin inherit from the class Any. Is this true?
sobes.tech AI
Answer from AI
Yes, that's correct. In Kotlin, as in Java, all classes implicitly inherit from a base class. In Kotlin, this class is Any.
// Example of class declaration
class MyClass {
// MyClass does not explicitly specify a superclass
// but it implicitly inherits from Any
}
The Any class provides a basic set of methods common to all objects:
equals(other: Any?): Boolean- for comparing objects for equality.hashCode(): Int- returns the hash code of the object.toString(): String- returns a string representation of the object.
These methods can be overridden in any class to provide specific implementations.