java anonymous class

i dont get what are anonymouss classes i dont get why interface method can be called whats wrong
20 Replies
JavaBot
JavaBot3y ago
This post has been reserved for your question.
Hey @eat1.! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
eat1.
eat1.OP3y ago
i dont get how interface methods can be called what is one use classes also
eat1.
eat1.OP3y ago
No description
eat1.
eat1.OP3y ago
here interfce method is called
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Kyo-chan
Kyo-chan3y ago
List<String> texts = List.of("Hello", "world");
String first = texts.get(0);
List<String> texts = List.of("Hello", "world");
String first = texts.get(0);
Like this
eat1.
eat1.OP3y ago
i am too confused lets say i have created interface Sound with methods void saySomething(); and i have Main class is it possible to create interface object ? like Sound animal = new Sound() sound is interface
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
eat1.
eat1.OP3y ago
then here why i can create interface object then call method
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
eat1.
eat1.OP3y ago
so anonymous classes are used to call interface methods is not it ?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
eat1.
eat1.OP3y ago
aaaah
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
eat1.
eat1.OP3y ago
so anonymous classes are used to implement interfaces right ?
Kyo-chan
Kyo-chan3y ago
Can also extend classes, but implementing interfaces is one way to use anonymous classes, yes
eat1.
eat1.OP3y ago
thanks guys
JavaBot
JavaBot3y ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot3y ago
Post Closed
This post has been closed by <@401165145327271976>.

Did you find this page helpful?