Junior — Middle
Is it possible to implement an anonymous class in a programming language?
sobes.tech AI
Answer from AI
Yes, in the Java programming language, which is widely used for Android application development, it is possible to implement anonymous classes. An anonymous class is a class without a name, which is declared and instantiated simultaneously, usually to implement an interface or extend a class with method overriding.
Example of an anonymous class in Java:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// handle click
}
});
Here, an anonymous class implementing the OnClickListener interface is created without explicitly declaring a separate class.