Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anonymous inner class must extend some superclass?

I am learning java swing and came across the concept of anonymous inner class. After studying a bit at this link, I feel that an anonymous inner class must always extend some other class since the method in which it gets passed as a parameter is predefined. At most, if a method accepts Object instances as parameter, only then we can create an anonymous independent inner class. I just seek your opinion whether I am right. It would be helpful if you could provide some example. Thanks in advance.

like image 959
Victor Mukherjee Avatar asked Oct 17 '25 13:10

Victor Mukherjee


1 Answers

Every class must extend some superclass. The only exception is java.lang.Object, which is the top-level class and thus can't have a superclass. Anonymous inner classes are no different in this regard.

like image 117
Jörg W Mittag Avatar answered Oct 19 '25 01:10

Jörg W Mittag