Sobes.tech
Junior — Middle

Is it possible to instantiate a class object that does not fully implement its functionalities?

sobes.tech AI

Answer from AI

In Java and Kotlin, you cannot instantiate an abstract class or interface directly if it does not implement all necessary functionalities. Abstract classes and interfaces serve as templates, and to use them, you need to create a subclass or implement the interface, providing concrete implementations of all abstract methods.

For example, in Kotlin:

abstract class Animal {
    abstract fun makeSound()
}

// Cannot instantiate Animal directly:
// val animal = Animal() // Error

// Need to create a subclass with implementation:
class Dog : Animal() {
    override fun makeSound() {
        println("Woof")
    }
}

val dog = Dog() // This is correct

Thus, an object of a class that does not fully implement the functionality (e.g., an abstract class without all methods implemented) cannot be instantiated.